CycleGAN, Image-to-Image Translation

In this notebook, we're going to define and train a CycleGAN to read in an image from a set $X$ and transform it so that it looks as if it belongs in set $Y$. Specifically, we'll look at a set of images of Yosemite national park taken either during the summer of winter. The seasons are our two domains!

The objective will be to train generators that learn to transform an image from domain $X$ into an image that looks like it came from domain $Y$ (and vice versa).

Some examples of image data in both sets are pictured below.

Unpaired Training Data

These images do not come with labels, but CycleGANs give us a way to learn the mapping between one image domain and another using an unsupervised approach. A CycleGAN is designed for image-to-image translation and it learns from unpaired training data. This means that in order to train a generator to translate images from domain $X$ to domain $Y$, we do not have to have exact correspondences between individual images in those domains. For example, in the paper that introduced CycleGANs, the authors are able to translate between images of horses and zebras, even though there are no images of a zebra in exactly the same position as a horse or with exactly the same background, etc. Thus, CycleGANs enable learning a mapping from one domain $X$ to another domain $Y$ without having to find perfectly-matched, training pairs!

CycleGAN and Notebook Structure

A CycleGAN is made of two types of networks: discriminators, and generators. In this example, the discriminators are responsible for classifying images as real or fake (for both $X$ and $Y$ kinds of images). The generators are responsible for generating convincing, fake images for both kinds of images.

This notebook will detail the steps you should take to define and train such a CycleGAN.

  1. You'll load in the image data using PyTorch's DataLoader class to efficiently read in images from a specified directory.
  2. Then, you'll be tasked with defining the CycleGAN architecture according to provided specifications. You'll define the discriminator and the generator models.
  3. You'll complete the training cycle by calculating the adversarial and cycle consistency losses for the generator and discriminator network and completing a number of training epochs. It's suggested that you enable GPU usage for training.
  4. Finally, you'll evaluate your model by looking at the loss over time and looking at sample, generated images.

Load and Visualize the Data

We'll first load in and visualize the training data, importing the necessary libraries to do so.

If you are working locally, you'll need to download the data as a zip file by clicking here.

It may be named summer2winter-yosemite/ with a dash or an underscore, so take note, extract the data to your home directory and make sure the below image_dir matches. Then you can proceed with the following loading code.

In [1]:
# loading in and transforming data
import os
import torch
from torch.utils.data import DataLoader
import torchvision
import torchvision.datasets as datasets
import torchvision.transforms as transforms

# visualizing data
import matplotlib.pyplot as plt
import numpy as np
import warnings

%matplotlib inline

DataLoaders

The get_data_loader function returns training and test DataLoaders that can load data efficiently and in specified batches. The function has the following parameters:

  • image_type: summer or winter, the names of the directories where the X and Y images are stored
  • image_dir: name of the main image directory, which holds all training and test images
  • image_size: resized, square image dimension (all images will be resized to this dim)
  • batch_size: number of images in one batch of data

The test data is strictly for feeding to our generators, later on, so we can visualize some generated samples on fixed, test data.

You can see that this function is also responsible for making sure our images are of the right, square size (128x128x3) and converted into Tensor image types.

It's suggested that you use the default values of these parameters.

Note: If you are trying this code on a different set of data, you may get better results with larger image_size and batch_size parameters. If you change the batch_size, make sure that you create complete batches in the training loop otherwise you may get an error when trying to save sample data.

In [2]:
def get_data_loader(image_type, image_dir='summer2winter_yosemite', 
                    image_size=128, batch_size=16, num_workers=0):
    """Returns training and test data loaders for a given image type, either 'summer' or 'winter'. 
       These images will be resized to 128x128x3, by default, converted into Tensors, and normalized.
    """
    
    # resize and normalize the images
    transform = transforms.Compose([transforms.Resize(image_size), # resize to 128x128
                                    transforms.ToTensor()])

    # get training and test directories
    image_path = './' + image_dir
    train_path = os.path.join(image_path, image_type)
    test_path = os.path.join(image_path, 'test_{}'.format(image_type))

    # define datasets using ImageFolder
    train_dataset = datasets.ImageFolder(train_path, transform)
    test_dataset = datasets.ImageFolder(test_path, transform)

    # create and return DataLoaders
    train_loader = DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True, num_workers=num_workers)
    test_loader = DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers)

    return train_loader, test_loader
In [3]:
# Create train and test dataloaders for images from the two domains X and Y
# image_type = directory names for our data
dataloader_X, test_dataloader_X = get_data_loader(image_type='summer')
dataloader_Y, test_dataloader_Y = get_data_loader(image_type='winter')

Display some Training Images

Below we provide a function imshow that reshape some given images and converts them to NumPy images so that they can be displayed by plt. This cell should display a grid that contains a batch of image data from set $X$.

In [4]:
# helper imshow function
def imshow(img):
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
    

# get some images from X
dataiter = iter(dataloader_X)
# the "_" is a placeholder for no labels
images, _ = dataiter.next()

# show images
fig = plt.figure(figsize=(15, 8))
imshow(torchvision.utils.make_grid(images))

Next, let's visualize a batch of images from set $Y$.

In [5]:
# get some images from Y
dataiter = iter(dataloader_Y)
images, _ = dataiter.next()

# show images
fig = plt.figure(figsize=(15,8))
imshow(torchvision.utils.make_grid(images))

Pre-processing: scaling from -1 to 1

We need to do a bit of pre-processing; we know that the output of our tanh activated generator will contain pixel values in a range from -1 to 1, and so, we need to rescale our training images to a range of -1 to 1. (Right now, they are in a range from 0-1.)

In [6]:
# current range
img = images[0]

print('Min: ', img.min())
print('Max: ', img.max())
Min:  tensor(0.)
Max:  tensor(0.9922)
In [7]:
# helper scale function
def scale(x, feature_range=(-1, 1)):
    ''' Scale takes in an image x and returns that image, scaled
       with a feature_range of pixel values from -1 to 1. 
       This function assumes that the input x is already scaled from 0-1.'''
    
    # scale from 0-1 to feature_range
    min, max = feature_range
    x = x * (max - min) + min
    return x
In [8]:
# scaled range
scaled_img = scale(img)

print('Scaled min: ', scaled_img.min())
print('Scaled max: ', scaled_img.max())
Scaled min:  tensor(-1.)
Scaled max:  tensor(0.9843)

Define the Model

A CycleGAN is made of two discriminator and two generator networks.

Discriminators

The discriminators, $D_X$ and $D_Y$, in this CycleGAN are convolutional neural networks that see an image and attempt to classify it as real or fake. In this case, real is indicated by an output close to 1 and fake as close to 0. The discriminators have the following architecture:

This network sees a 128x128x3 image, and passes it through 5 convolutional layers that downsample the image by a factor of 2. The first four convolutional layers have a BatchNorm and ReLu activation function applied to their output, and the last acts as a classification layer that outputs one value.

Convolutional Helper Function

To define the discriminators, you're expected to use the provided conv function, which creates a convolutional layer + an optional batch norm layer.

In [9]:
import torch.nn as nn
import torch.nn.functional as F

# helper conv function
def conv(in_channels, out_channels, kernel_size, stride=2, padding=1, batch_norm=True):
    """Creates a convolutional layer, with optional batch normalization.
    """
    layers = []
    conv_layer = nn.Conv2d(in_channels=in_channels, out_channels=out_channels, 
                           kernel_size=kernel_size, stride=stride, padding=padding, bias=False)
    
    layers.append(conv_layer)

    if batch_norm:
        layers.append(nn.BatchNorm2d(out_channels))
    return nn.Sequential(*layers)

Define the Discriminator Architecture

Your task is to fill in the __init__ function with the specified 5 layer conv net architecture. Both $D_X$ and $D_Y$ have the same architecture, so we only need to define one class, and later instantiate two discriminators.

It's recommended that you use a kernel size of 4x4 and use that to determine the correct stride and padding size for each layer. This Stanford resource may also help in determining stride and padding sizes.

  • Define your convolutional layers in __init__
  • Then fill in the forward behavior of the network

The forward function defines how an input image moves through the discriminator, and the most important thing is to pass it through your convolutional layers in order, with a ReLu activation function applied to all but the last layer.

You should not apply a sigmoid activation function to the output, here, and that is because we are planning on using a squared error loss for training. And you can read more about this loss function, later in the notebook.

In [10]:
class Discriminator(nn.Module):
    
    def __init__(self, conv_dim=64):
        super(Discriminator, self).__init__()

        # Define all convolutional layers
        # Should accept an RGB image as input and output a single value
        self.layer_1 = conv(3,conv_dim,4,batch_norm = False)
        self.layer_2 = conv(conv_dim,conv_dim*2,4)
        self.layer_3 = conv(conv_dim*2,conv_dim*4,4)
        self.layer_4 = conv(conv_dim*4,conv_dim*8,4)
        self.layer_5 = conv(conv_dim*8,1,4,1,batch_norm = False)

    def forward(self, x):
        # define feedforward behavior
        x = F.relu(self.layer_1(x))
        x = F.relu(self.layer_2(x))
        x = F.relu(self.layer_3(x))
        x = F.relu(self.layer_4(x))
        
        x = self.layer_5(x)
        return x

Generators

The generators, G_XtoY and G_YtoX (sometimes called F), are made of an encoder, a conv net that is responsible for turning an image into a smaller feature representation, and a decoder, a transpose_conv net that is responsible for turning that representation into an transformed image. These generators, one from XtoY and one from YtoX, have the following architecture:

This network sees a 128x128x3 image, compresses it into a feature representation as it goes through three convolutional layers and reaches a series of residual blocks. It goes through a few (typically 6 or more) of these residual blocks, then it goes through three transpose convolutional layers (sometimes called de-conv layers) which upsample the output of the resnet blocks and create a new image!

Note that most of the convolutional and transpose-convolutional layers have BatchNorm and ReLu functions applied to their outputs with the exception of the final transpose convolutional layer, which has a tanh activation function applied to the output. Also, the residual blocks are made of convolutional and batch normalization layers, which we'll go over in more detail, next.


Residual Block Class

To define the generators, you're expected to define a ResidualBlock class which will help you connect the encoder and decoder portions of the generators. You might be wondering, what exactly is a Resnet block? It may sound familiar from something like ResNet50 for image classification, pictured below.

ResNet blocks rely on connecting the output of one layer with the input of an earlier layer. The motivation for this structure is as follows: very deep neural networks can be difficult to train. Deeper networks are more likely to have vanishing or exploding gradients and, therefore, have trouble reaching convergence; batch normalization helps with this a bit. However, during training, we often see that deep networks respond with a kind of training degradation. Essentially, the training accuracy stops improving and gets saturated at some point during training. In the worst cases, deep models would see their training accuracy actually worsen over time!

One solution to this problem is to use Resnet blocks that allow us to learn so-called residual functions as they are applied to layer inputs. You can read more about this proposed architecture in the paper, Deep Residual Learning for Image Recognition by Kaiming He et. al, and the below image is from that paper.

Residual Functions

Usually, when we create a deep learning model, the model (several layers with activations applied) is responsible for learning a mapping, M, from an input x to an output y.

M(x) = y (Equation 1)

Instead of learning a direct mapping from x to y, we can instead define a residual function

F(x) = M(x) - x

This looks at the difference between a mapping applied to x and the original input, x. F(x) is, typically, two convolutional layers + normalization layer and a ReLu in between. These convolutional layers should have the same number of inputs as outputs. This mapping can then be written as the following; a function of the residual function and the input x. The addition step creates a kind of loop that connects the input x to the output, y:

M(x) = F(x) + x (Equation 2) or

y = F(x) + x (Equation 3)

Optimizing a Residual Function

The idea is that it is easier to optimize this residual function F(x) than it is to optimize the original mapping M(x). Consider an example; what if we want y = x?

From our first, direct mapping equation, Equation 1, we could set M(x) = x but it is easier to solve the residual equation F(x) = 0, which, when plugged in to Equation 3, yields y = x.

Defining the ResidualBlock Class

To define the ResidualBlock class, we'll define residual functions (a series of layers), apply them to an input x and add them to that same input. This is defined just like any other neural network, with an __init__ function and the addition step in the forward function.

In our case, you'll want to define the residual block as:

  • Two convolutional layers with the same size input and output
  • Batch normalization applied to the outputs of the convolutional layers
  • A ReLu function on the output of the first convolutional layer

Then, in the forward function, add the input x to this residual block. Feel free to use the helper conv function from above to create this block.

In [11]:
# residual block class
class ResidualBlock(nn.Module):
    """Defines a residual block.
       This adds an input x to a convolutional layer (applied to x) with the same size input and output.
       These blocks allow a model to learn an effective transformation from one domain to another.
    """
    def __init__(self, conv_dim):
        super(ResidualBlock, self).__init__()
        # conv_dim = number of inputs  
        
        # define two convolutional layers + batch normalization that will act as our residual function, F(x)
        # layers should have the same shape input as output; I suggest a kernel_size of 3
        self.layer_1 = conv(conv_dim,conv_dim,3,1,1,batch_norm = True)
        self.layer_2 = conv(conv_dim,conv_dim,3,1,1,batch_norm = True)
        
    def forward(self, x):
        # apply a ReLu activation the outputs of the first layer
        # return a summed output, x + resnet_block(x)
        out_1 = F.relu(self.layer_1(x))
        out_2 = x + self.layer_2(out_1)
        
        return out_2
    

Transpose Convolutional Helper Function

To define the generators, you're expected to use the above conv function, ResidualBlock class, and the below deconv helper function, which creates a transpose convolutional layer + an optional batchnorm layer.

In [12]:
# helper deconv function
def deconv(in_channels, out_channels, kernel_size, stride=2, padding=1, batch_norm=True):
    """Creates a transpose convolutional layer, with optional batch normalization.
    """
    layers = []
    # append transpose conv layer
    layers.append(nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride, padding, bias=False))
    # optional batch norm layer
    if batch_norm:
        layers.append(nn.BatchNorm2d(out_channels))
    return nn.Sequential(*layers)

Define the Generator Architecture

  • Complete the __init__ function with the specified 3 layer encoder convolutional net, a series of residual blocks (the number of which is given by n_res_blocks), and then a 3 layer decoder transpose convolutional net.
  • Then complete the forward function to define the forward behavior of the generators. Recall that the last layer has a tanh activation function.

Both $G_{XtoY}$ and $G_{YtoX}$ have the same architecture, so we only need to define one class, and later instantiate two generators.

In [13]:
class CycleGenerator(nn.Module):
    
    def __init__(self, conv_dim=64, n_res_blocks=6):
        super(CycleGenerator, self).__init__()

        # 1. Define the encoder part of the generator
        self.layer_1 = conv(3,conv_dim,4)
        self.layer_2 = conv(conv_dim,conv_dim*2,4)
        self.layer_3 = conv(conv_dim*2,conv_dim*4,4)
        # 2. Define the resnet part of the generator
        layers = []
        for n in range(n_res_blocks):
            layers.append(ResidualBlock(conv_dim*4))
        self.res_blocks = nn.Sequential(*layers)
        # 3. Define the decoder part of the generator
        self.layer_4 = deconv(conv_dim*4,conv_dim*2,4)
        self.layer_5 = deconv(conv_dim*2,conv_dim,4)
        self.layer_6 = deconv(conv_dim,3,4,batch_norm = False)

    def forward(self, x):
        """Given an image x, returns a transformed image."""
        # define feedforward behavior, applying activations as necessary
        
        out = F.relu(self.layer_1(x))
        out = F.relu(self.layer_2(out))
        out = F.relu(self.layer_3(out))
        
        out = self.res_blocks(out)
        
        out = F.relu(self.layer_4(out))
        out = F.relu(self.layer_5(out))
        out = F.tanh(self.layer_6(out))
        
        return out

Create the complete network

Using the classes you defined earlier, you can define the discriminators and generators necessary to create a complete CycleGAN. The given parameters should work for training.

First, create two discriminators, one for checking if $X$ sample images are real, and one for checking if $Y$ sample images are real. Then the generators. Instantiate two of them, one for transforming a painting into a realistic photo and one for transforming a photo into into a painting.

In [14]:
def create_model(g_conv_dim=64, d_conv_dim=64, n_res_blocks=6):
    """Builds the generators and discriminators."""
    
    # Instantiate generators
    G_XtoY = CycleGenerator(g_conv_dim,n_res_blocks)
    G_YtoX = CycleGenerator(g_conv_dim,n_res_blocks)
    # Instantiate discriminators
    D_X = Discriminator(d_conv_dim)
    D_Y = Discriminator(d_conv_dim)
    

    # move models to GPU, if available
    if torch.cuda.is_available():
        device = torch.device("cuda:0")
        G_XtoY.to(device)
        G_YtoX.to(device)
        D_X.to(device)
        D_Y.to(device)
        print('Models moved to GPU.')
    else:
        print('Only CPU available.')

    return G_XtoY, G_YtoX, D_X, D_Y
In [15]:
# call the function to get models
G_XtoY, G_YtoX, D_X, D_Y = create_model()
Models moved to GPU.

Check that you've implemented this correctly

The function create_model should return the two generator and two discriminator networks. After you've defined these discriminator and generator components, it's good practice to check your work. The easiest way to do this is to print out your model architecture and read through it to make sure the parameters are what you expected. The next cell will print out their architectures.

In [16]:
# helper function for printing the model architecture
def print_models(G_XtoY, G_YtoX, D_X, D_Y):
    """Prints model information for the generators and discriminators.
    """
    print("                     G_XtoY                    ")
    print("-----------------------------------------------")
    print(G_XtoY)
    print()

    print("                     G_YtoX                    ")
    print("-----------------------------------------------")
    print(G_YtoX)
    print()

    print("                      D_X                      ")
    print("-----------------------------------------------")
    print(D_X)
    print()

    print("                      D_Y                      ")
    print("-----------------------------------------------")
    print(D_Y)
    print()
    

# print all of the models
print_models(G_XtoY, G_YtoX, D_X, D_Y)
                     G_XtoY                    
-----------------------------------------------
CycleGenerator(
  (layer_1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (res_blocks): Sequential(
    (0): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (2): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (3): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (4): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (layer_4): Sequential(
    (0): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_5): Sequential(
    (0): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_6): Sequential(
    (0): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
)

                     G_YtoX                    
-----------------------------------------------
CycleGenerator(
  (layer_1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (res_blocks): Sequential(
    (0): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (2): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (3): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (4): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): ResidualBlock(
      (layer_1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (layer_2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (layer_4): Sequential(
    (0): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_5): Sequential(
    (0): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_6): Sequential(
    (0): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
)

                      D_X                      
-----------------------------------------------
Discriminator(
  (layer_1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
  (layer_2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_4): Sequential(
    (0): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_5): Sequential(
    (0): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
  )
)

                      D_Y                      
-----------------------------------------------
Discriminator(
  (layer_1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
  (layer_2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_4): Sequential(
    (0): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (layer_5): Sequential(
    (0): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
  )
)

Discriminator and Generator Losses

Computing the discriminator and the generator losses are key to getting a CycleGAN to train.

Image from original paper by Jun-Yan Zhu et. al.

  • The CycleGAN contains two mapping functions $G: X \rightarrow Y$ and $F: Y \rightarrow X$, and associated adversarial discriminators $D_Y$ and $D_X$. (a) $D_Y$ encourages $G$ to translate $X$ into outputs indistinguishable from domain $Y$, and vice versa for $D_X$ and $F$.

  • To further regularize the mappings, we introduce two cycle consistency losses that capture the intuition that if we translate from one domain to the other and back again we should arrive at where we started. (b) Forward cycle-consistency loss and (c) backward cycle-consistency loss.

Least Squares GANs

We've seen that regular GANs treat the discriminator as a classifier with the sigmoid cross entropy loss function. However, this loss function may lead to the vanishing gradients problem during the learning process. To overcome such a problem, we'll use a least squares loss function for the discriminator. This structure is also referred to as a least squares GAN or LSGAN, and you can read the original paper on LSGANs, here. The authors show that LSGANs are able to generate higher quality images than regular GANs and that this loss type is a bit more stable during training!

Discriminator Losses

The discriminator losses will be mean squared errors between the output of the discriminator, given an image, and the target value, 0 or 1, depending on whether it should classify that image as fake or real. For example, for a real image, x, we can train $D_X$ by looking at how close it is to recognizing and image x as real using the mean squared error:

out_x = D_X(x)
real_err = torch.mean((out_x-1)**2)

Generator Losses

Calculating the generator losses will look somewhat similar to calculating the discriminator loss; there will still be steps in which you generate fake images that look like they belong to the set of $X$ images but are based on real images in set $Y$, and vice versa. You'll compute the "real loss" on those generated images by looking at the output of the discriminator as it's applied to these fake images; this time, your generator aims to make the discriminator classify these fake images as real images.

Cycle Consistency Loss

In addition to the adversarial losses, the generator loss terms will also include the cycle consistency loss. This loss is a measure of how good a reconstructed image is, when compared to an original image.

Say you have a fake, generated image, x_hat, and a real image, y. You can get a reconstructed y_hat by applying G_XtoY(x_hat) = y_hat and then check to see if this reconstruction y_hat and the orginal image y match. For this, we recommed calculating the L1 loss, which is an absolute difference, between reconstructed and real images. You may also choose to multiply this loss by some weight value lambda_weight to convey its importance.

The total generator loss will be the sum of the generator losses and the forward and backward cycle consistency losses.


Define Loss Functions

To help us calculate the discriminator and gnerator losses during training, let's define some helpful loss functions. Here, we'll define three.

  1. real_mse_loss that looks at the output of a discriminator and returns the error based on how close that output is to being classified as real. This should be a mean squared error.
  2. fake_mse_loss that looks at the output of a discriminator and returns the error based on how close that output is to being classified as fake. This should be a mean squared error.
  3. cycle_consistency_loss that looks at a set of real image and a set of reconstructed/generated images, and returns the mean absolute error between them. This has a lambda_weight parameter that will weight the mean absolute error in a batch.

It's recommended that you take a look at the original, CycleGAN paper to get a starting value for lambda_weight.

In [17]:
def real_mse_loss(D_out):
    # how close is the produced output from being "real"?
    return torch.mean((D_out - 1)**2)

    
def fake_mse_loss(D_out):
    # how close is the produced output from being "fake"?
    return torch.mean(D_out**2)

def cycle_consistency_loss(real_im, reconstructed_im, lambda_weight):
    # calculate reconstruction loss 
    # return weighted loss
    loss = torch.mean(torch.abs(real_im - reconstructed_im))
    return loss*lambda_weight

Define the Optimizers

Next, let's define how this model will update its weights. This, like the GANs you may have seen before, uses Adam optimizers for the discriminator and generator. It's again recommended that you take a look at the original, CycleGAN paper to get starting hyperparameter values.

In [18]:
import torch.optim as optim

# hyperparams for Adam optimizers
lr= 0.0002
beta1= 0.5
beta2= 0.999

g_params = list(G_XtoY.parameters()) + list(G_YtoX.parameters())  # Get generator parameters

# Create optimizers for the generators and discriminators
g_optimizer = optim.Adam(g_params, lr, [beta1, beta2])
d_x_optimizer = optim.Adam(D_X.parameters(), lr, [beta1, beta2])
d_y_optimizer = optim.Adam(D_Y.parameters(), lr, [beta1, beta2])

Training a CycleGAN

When a CycleGAN trains, and sees one batch of real images from set $X$ and $Y$, it trains by performing the following steps:

Training the Discriminators

  1. Compute the discriminator $D_X$ loss on real images
  2. Generate fake images that look like domain $X$ based on real images in domain $Y$
  3. Compute the fake loss for $D_X$
  4. Compute the total loss and perform backpropagation and $D_X$ optimization
  5. Repeat steps 1-4 only with $D_Y$ and your domains switched!

Training the Generators

  1. Generate fake images that look like domain $X$ based on real images in domain $Y$
  2. Compute the generator loss based on how $D_X$ responds to fake $X$
  3. Generate reconstructed $\hat{Y}$ images based on the fake $X$ images generated in step 1
  4. Compute the cycle consistency loss by comparing the reconstructions with real $Y$ images
  5. Repeat steps 1-4 only swapping domains
  6. Add up all the generator and reconstruction losses and perform backpropagation + optimization

Saving Your Progress

A CycleGAN repeats its training process, alternating between training the discriminators and the generators, for a specified number of training iterations. You've been given code that will save some example generated images that the CycleGAN has learned to generate after a certain number of training iterations. Along with looking at the losses, these example generations should give you an idea of how well your network has trained.

Below, you may choose to keep all default parameters; your only task is to calculate the appropriate losses and complete the training cycle.

In [19]:
# import save code
from helpers import save_samples, checkpoint
In [20]:
# train the network
def training_loop(dataloader_X, dataloader_Y, test_dataloader_X, test_dataloader_Y, 
                  n_epochs=1000):
    
    print_every=10
    
    # keep track of losses over time
    losses = []

    test_iter_X = iter(test_dataloader_X)
    test_iter_Y = iter(test_dataloader_Y)

    # Get some fixed data from domains X and Y for sampling. These are images that are held
    # constant throughout training, that allow us to inspect the model's performance.
    fixed_X = test_iter_X.next()[0]
    fixed_Y = test_iter_Y.next()[0]
    fixed_X = scale(fixed_X) # make sure to scale to a range -1 to 1
    fixed_Y = scale(fixed_Y)

    # batches per epoch
    iter_X = iter(dataloader_X)
    iter_Y = iter(dataloader_Y)
    batches_per_epoch = min(len(iter_X), len(iter_Y))

    for epoch in range(1, n_epochs+1):

        # Reset iterators for each epoch
        if epoch % batches_per_epoch == 0:
            iter_X = iter(dataloader_X)
            iter_Y = iter(dataloader_Y)

        images_X, _ = iter_X.next()
        images_X = scale(images_X) # make sure to scale to a range -1 to 1

        images_Y, _ = iter_Y.next()
        images_Y = scale(images_Y)
        
        # move images to GPU if available (otherwise stay on CPU)
        device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
        images_X = images_X.to(device)
        images_Y = images_Y.to(device)


        # ============================================
        #            TRAIN THE DISCRIMINATORS
        # ============================================

        ##   First: D_X, real and fake loss components   ##

        # 1. Compute the discriminator losses on real images
        d_x_optimizer.zero_grad()
        real_D_loss = real_mse_loss(D_X(images_X))
        # 3. Compute the fake loss for D_X
        fake_D_loss = fake_mse_loss(D_X(G_YtoX(images_Y)))
        # 4. Compute the total loss and perform backprop
        d_x_loss = real_D_loss + fake_D_loss
        d_x_loss.backward()
        d_x_optimizer.step()
        
        ##   Second: D_Y, real and fake loss components   ##
        d_y_optimizer.zero_grad()
        real_D_y_loss = real_mse_loss(D_Y(images_Y))
        
        fake_D_y_loss = fake_mse_loss(D_Y(G_XtoY(images_X)))
        
        d_y_loss = real_D_y_loss + fake_D_y_loss
        d_y_loss.backward()
        d_y_optimizer.step()


        # =========================================
        #            TRAIN THE GENERATORS
        # =========================================

        ##    First: generate fake X images and reconstructed Y images    ##
        g_optimizer.zero_grad()
        # 1. Generate fake images that look like domain X based on real images in domain Y
        out_1 = G_YtoX(images_Y)
        # 2. Compute the generator loss based on domain X
        loss_1 = real_mse_loss(D_X(out_1))
        # 3. Create a reconstructed y
        out_2 = G_XtoY(out_1)
        # 4. Compute the cycle consistency loss (the reconstruction loss)
        loss_2 = cycle_consistency_loss(real_im = images_Y, reconstructed_im = out_2, lambda_weight=10)

        ##    Second: generate fake Y images and reconstructed X images    ##
        out_3 = G_XtoY(images_X)
        # 5. Add up all generator and reconstructed losses and perform backprop
        loss_3 = real_mse_loss(D_Y(out_3))
        out_4 = G_YtoX(out_3)
        loss_4 =  cycle_consistency_loss(real_im = images_X, reconstructed_im = out_4, lambda_weight=10)

        g_total_loss = loss_1 + loss_2 + loss_3 + loss_4
        g_total_loss.backward()
        g_optimizer.step()
        
        # Print the log info
        if epoch % print_every == 0:
            # append real and fake discriminator losses and the generator loss
            losses.append((d_x_loss.item(), d_y_loss.item(), g_total_loss.item()))
            print('Epoch [{:5d}/{:5d}] | d_X_loss: {:6.4f} | d_Y_loss: {:6.4f} | g_total_loss: {:6.4f}'.format(
                    epoch, n_epochs, d_x_loss.item(), d_y_loss.item(), g_total_loss.item()))

            
        sample_every=100
        # Save the generated samples
        if epoch % sample_every == 0:
            G_YtoX.eval() # set generators to eval mode for sample generation
            G_XtoY.eval()
            save_samples(epoch, fixed_Y, fixed_X, G_YtoX, G_XtoY, batch_size=16)
            G_YtoX.train()
            G_XtoY.train()

        # uncomment these lines, if you want to save your model
#         checkpoint_every=1000
#         # Save the model parameters
#         if epoch % checkpoint_every == 0:
#             checkpoint(epoch, G_XtoY, G_YtoX, D_X, D_Y)

    return losses
In [21]:
n_epochs = 5000 # keep this small when testing if a model first works, then increase it to >=1000

losses = training_loop(dataloader_X, dataloader_Y, test_dataloader_X, test_dataloader_Y, n_epochs=n_epochs)
Epoch [   10/ 5000] | d_X_loss: 0.2088 | d_Y_loss: 0.1823 | g_total_loss: 9.3729
Epoch [   20/ 5000] | d_X_loss: 0.2060 | d_Y_loss: 0.1589 | g_total_loss: 8.4486
Epoch [   30/ 5000] | d_X_loss: 0.6348 | d_Y_loss: 0.3463 | g_total_loss: 6.6383
Epoch [   40/ 5000] | d_X_loss: 0.3169 | d_Y_loss: 0.3987 | g_total_loss: 6.7907
Epoch [   50/ 5000] | d_X_loss: 0.2488 | d_Y_loss: 0.4649 | g_total_loss: 6.6019
Epoch [   60/ 5000] | d_X_loss: 0.4253 | d_Y_loss: 0.3704 | g_total_loss: 5.7399
Epoch [   70/ 5000] | d_X_loss: 0.4239 | d_Y_loss: 0.4891 | g_total_loss: 5.0592
Epoch [   80/ 5000] | d_X_loss: 0.4233 | d_Y_loss: 0.5069 | g_total_loss: 5.5218
Epoch [   90/ 5000] | d_X_loss: 0.4811 | d_Y_loss: 0.5497 | g_total_loss: 4.3656
Epoch [  100/ 5000] | d_X_loss: 0.4386 | d_Y_loss: 0.4556 | g_total_loss: 4.4615
Saved samples_cyclegan/sample-000100-X-Y.png
Saved samples_cyclegan/sample-000100-Y-X.png
Epoch [  110/ 5000] | d_X_loss: 0.4470 | d_Y_loss: 0.4353 | g_total_loss: 4.4624
Epoch [  120/ 5000] | d_X_loss: 0.4183 | d_Y_loss: 0.3908 | g_total_loss: 4.5977
Epoch [  130/ 5000] | d_X_loss: 0.4085 | d_Y_loss: 0.4080 | g_total_loss: 4.0547
Epoch [  140/ 5000] | d_X_loss: 0.4361 | d_Y_loss: 0.4897 | g_total_loss: 4.4623
Epoch [  150/ 5000] | d_X_loss: 0.4347 | d_Y_loss: 0.4394 | g_total_loss: 4.7017
Epoch [  160/ 5000] | d_X_loss: 0.5951 | d_Y_loss: 0.5162 | g_total_loss: 3.6939
Epoch [  170/ 5000] | d_X_loss: 0.3621 | d_Y_loss: 0.3839 | g_total_loss: 4.8712
Epoch [  180/ 5000] | d_X_loss: 0.3795 | d_Y_loss: 0.3083 | g_total_loss: 5.5614
Epoch [  190/ 5000] | d_X_loss: 0.3165 | d_Y_loss: 0.4199 | g_total_loss: 4.6277
Epoch [  200/ 5000] | d_X_loss: 0.3852 | d_Y_loss: 0.3490 | g_total_loss: 4.4693
Saved samples_cyclegan/sample-000200-X-Y.png
Saved samples_cyclegan/sample-000200-Y-X.png
Epoch [  210/ 5000] | d_X_loss: 0.4968 | d_Y_loss: 0.5989 | g_total_loss: 4.0137
Epoch [  220/ 5000] | d_X_loss: 0.2517 | d_Y_loss: 0.2260 | g_total_loss: 4.9777
Epoch [  230/ 5000] | d_X_loss: 0.4613 | d_Y_loss: 0.3844 | g_total_loss: 4.8094
Epoch [  240/ 5000] | d_X_loss: 0.4140 | d_Y_loss: 0.3850 | g_total_loss: 4.5848
Epoch [  250/ 5000] | d_X_loss: 0.3573 | d_Y_loss: 0.2793 | g_total_loss: 4.2538
Epoch [  260/ 5000] | d_X_loss: 0.4827 | d_Y_loss: 0.3371 | g_total_loss: 4.5269
Epoch [  270/ 5000] | d_X_loss: 0.3664 | d_Y_loss: 0.3468 | g_total_loss: 4.6832
Epoch [  280/ 5000] | d_X_loss: 0.4416 | d_Y_loss: 0.6397 | g_total_loss: 3.8225
Epoch [  290/ 5000] | d_X_loss: 0.3722 | d_Y_loss: 0.4122 | g_total_loss: 4.2695
Epoch [  300/ 5000] | d_X_loss: 0.2628 | d_Y_loss: 0.3841 | g_total_loss: 4.0817
Saved samples_cyclegan/sample-000300-X-Y.png
Saved samples_cyclegan/sample-000300-Y-X.png
Epoch [  310/ 5000] | d_X_loss: 0.3614 | d_Y_loss: 0.3712 | g_total_loss: 4.5763
Epoch [  320/ 5000] | d_X_loss: 0.3912 | d_Y_loss: 0.3828 | g_total_loss: 4.2286
Epoch [  330/ 5000] | d_X_loss: 0.4306 | d_Y_loss: 0.5432 | g_total_loss: 3.2321
Epoch [  340/ 5000] | d_X_loss: 0.3798 | d_Y_loss: 0.4570 | g_total_loss: 4.4931
Epoch [  350/ 5000] | d_X_loss: 0.4248 | d_Y_loss: 0.4206 | g_total_loss: 4.1924
Epoch [  360/ 5000] | d_X_loss: 0.2317 | d_Y_loss: 0.2539 | g_total_loss: 5.3464
Epoch [  370/ 5000] | d_X_loss: 0.1831 | d_Y_loss: 0.4543 | g_total_loss: 3.7815
Epoch [  380/ 5000] | d_X_loss: 0.4124 | d_Y_loss: 0.4432 | g_total_loss: 4.1738
Epoch [  390/ 5000] | d_X_loss: 0.4144 | d_Y_loss: 0.3749 | g_total_loss: 5.0886
Epoch [  400/ 5000] | d_X_loss: 0.3863 | d_Y_loss: 0.4562 | g_total_loss: 4.0461
Saved samples_cyclegan/sample-000400-X-Y.png
Saved samples_cyclegan/sample-000400-Y-X.png
Epoch [  410/ 5000] | d_X_loss: 0.3624 | d_Y_loss: 0.3838 | g_total_loss: 3.7050
Epoch [  420/ 5000] | d_X_loss: 0.4022 | d_Y_loss: 0.4242 | g_total_loss: 3.6304
Epoch [  430/ 5000] | d_X_loss: 0.3684 | d_Y_loss: 0.3889 | g_total_loss: 4.6154
Epoch [  440/ 5000] | d_X_loss: 0.3518 | d_Y_loss: 0.3625 | g_total_loss: 4.3949
Epoch [  450/ 5000] | d_X_loss: 0.8717 | d_Y_loss: 0.5902 | g_total_loss: 4.8858
Epoch [  460/ 5000] | d_X_loss: 0.2615 | d_Y_loss: 0.3861 | g_total_loss: 4.2946
Epoch [  470/ 5000] | d_X_loss: 0.4215 | d_Y_loss: 0.2234 | g_total_loss: 5.0485
Epoch [  480/ 5000] | d_X_loss: 0.3244 | d_Y_loss: 0.2903 | g_total_loss: 4.9649
Epoch [  490/ 5000] | d_X_loss: 0.3389 | d_Y_loss: 0.3537 | g_total_loss: 4.1211
Epoch [  500/ 5000] | d_X_loss: 0.2966 | d_Y_loss: 0.4763 | g_total_loss: 5.4180
Saved samples_cyclegan/sample-000500-X-Y.png
Saved samples_cyclegan/sample-000500-Y-X.png
Epoch [  510/ 5000] | d_X_loss: 0.3595 | d_Y_loss: 0.3983 | g_total_loss: 4.0436
Epoch [  520/ 5000] | d_X_loss: 0.3038 | d_Y_loss: 0.2779 | g_total_loss: 4.9477
Epoch [  530/ 5000] | d_X_loss: 0.2862 | d_Y_loss: 0.5017 | g_total_loss: 3.9609
Epoch [  540/ 5000] | d_X_loss: 0.3045 | d_Y_loss: 0.4532 | g_total_loss: 3.9895
Epoch [  550/ 5000] | d_X_loss: 0.4525 | d_Y_loss: 0.3344 | g_total_loss: 4.2207
Epoch [  560/ 5000] | d_X_loss: 0.3597 | d_Y_loss: 0.4456 | g_total_loss: 4.4172
Epoch [  570/ 5000] | d_X_loss: 0.2817 | d_Y_loss: 0.7353 | g_total_loss: 4.1383
Epoch [  580/ 5000] | d_X_loss: 0.5626 | d_Y_loss: 0.5634 | g_total_loss: 3.6610
Epoch [  590/ 5000] | d_X_loss: 0.2908 | d_Y_loss: 0.4979 | g_total_loss: 4.2644
Epoch [  600/ 5000] | d_X_loss: 0.3406 | d_Y_loss: 0.4634 | g_total_loss: 3.8825
Saved samples_cyclegan/sample-000600-X-Y.png
Saved samples_cyclegan/sample-000600-Y-X.png
Epoch [  610/ 5000] | d_X_loss: 0.5142 | d_Y_loss: 0.4847 | g_total_loss: 3.6398
Epoch [  620/ 5000] | d_X_loss: 0.3639 | d_Y_loss: 0.3477 | g_total_loss: 3.9721
Epoch [  630/ 5000] | d_X_loss: 0.4558 | d_Y_loss: 0.5033 | g_total_loss: 4.1815
Epoch [  640/ 5000] | d_X_loss: 0.3639 | d_Y_loss: 0.4796 | g_total_loss: 4.1147
Epoch [  650/ 5000] | d_X_loss: 0.4347 | d_Y_loss: 0.5267 | g_total_loss: 5.9442
Epoch [  660/ 5000] | d_X_loss: 0.2146 | d_Y_loss: 0.3339 | g_total_loss: 3.8400
Epoch [  670/ 5000] | d_X_loss: 0.2038 | d_Y_loss: 0.3893 | g_total_loss: 4.6211
Epoch [  680/ 5000] | d_X_loss: 0.2687 | d_Y_loss: 0.3566 | g_total_loss: 4.2867
Epoch [  690/ 5000] | d_X_loss: 0.3066 | d_Y_loss: 0.4235 | g_total_loss: 4.2650
Epoch [  700/ 5000] | d_X_loss: 0.8782 | d_Y_loss: 0.4061 | g_total_loss: 5.0126
Saved samples_cyclegan/sample-000700-X-Y.png
Saved samples_cyclegan/sample-000700-Y-X.png
Epoch [  710/ 5000] | d_X_loss: 0.2759 | d_Y_loss: 0.4715 | g_total_loss: 4.6557
Epoch [  720/ 5000] | d_X_loss: 0.3831 | d_Y_loss: 0.4658 | g_total_loss: 4.3080
Epoch [  730/ 5000] | d_X_loss: 0.3654 | d_Y_loss: 0.3760 | g_total_loss: 3.8508
Epoch [  740/ 5000] | d_X_loss: 0.3889 | d_Y_loss: 0.2994 | g_total_loss: 4.5884
Epoch [  750/ 5000] | d_X_loss: 0.3144 | d_Y_loss: 0.3349 | g_total_loss: 5.0295
Epoch [  760/ 5000] | d_X_loss: 0.2583 | d_Y_loss: 0.3982 | g_total_loss: 4.7117
Epoch [  770/ 5000] | d_X_loss: 0.2688 | d_Y_loss: 0.5537 | g_total_loss: 3.9954
Epoch [  780/ 5000] | d_X_loss: 0.2798 | d_Y_loss: 0.3545 | g_total_loss: 4.6455
Epoch [  790/ 5000] | d_X_loss: 0.6678 | d_Y_loss: 0.3515 | g_total_loss: 4.2656
Epoch [  800/ 5000] | d_X_loss: 0.2158 | d_Y_loss: 0.1419 | g_total_loss: 4.5048
Saved samples_cyclegan/sample-000800-X-Y.png
Saved samples_cyclegan/sample-000800-Y-X.png
Epoch [  810/ 5000] | d_X_loss: 0.3944 | d_Y_loss: 0.2512 | g_total_loss: 4.6207
Epoch [  820/ 5000] | d_X_loss: 0.3513 | d_Y_loss: 0.4221 | g_total_loss: 4.6233
Epoch [  830/ 5000] | d_X_loss: 0.3747 | d_Y_loss: 0.3008 | g_total_loss: 4.0193
Epoch [  840/ 5000] | d_X_loss: 0.3135 | d_Y_loss: 0.3967 | g_total_loss: 3.5552
Epoch [  850/ 5000] | d_X_loss: 0.3131 | d_Y_loss: 0.5601 | g_total_loss: 5.3099
Epoch [  860/ 5000] | d_X_loss: 0.3704 | d_Y_loss: 0.3608 | g_total_loss: 4.3724
Epoch [  870/ 5000] | d_X_loss: 0.2621 | d_Y_loss: 0.3626 | g_total_loss: 4.3409
Epoch [  880/ 5000] | d_X_loss: 0.2902 | d_Y_loss: 0.2652 | g_total_loss: 4.5709
Epoch [  890/ 5000] | d_X_loss: 0.2923 | d_Y_loss: 0.3756 | g_total_loss: 4.3119
Epoch [  900/ 5000] | d_X_loss: 0.6095 | d_Y_loss: 0.3008 | g_total_loss: 4.4312
Saved samples_cyclegan/sample-000900-X-Y.png
Saved samples_cyclegan/sample-000900-Y-X.png
Epoch [  910/ 5000] | d_X_loss: 0.2834 | d_Y_loss: 0.3907 | g_total_loss: 3.8839
Epoch [  920/ 5000] | d_X_loss: 0.2840 | d_Y_loss: 0.3451 | g_total_loss: 4.2399
Epoch [  930/ 5000] | d_X_loss: 0.2328 | d_Y_loss: 0.3765 | g_total_loss: 4.4518
Epoch [  940/ 5000] | d_X_loss: 0.9649 | d_Y_loss: 0.4799 | g_total_loss: 4.0363
Epoch [  950/ 5000] | d_X_loss: 0.2806 | d_Y_loss: 0.3404 | g_total_loss: 3.6964
Epoch [  960/ 5000] | d_X_loss: 0.3546 | d_Y_loss: 0.3015 | g_total_loss: 3.8343
Epoch [  970/ 5000] | d_X_loss: 0.2563 | d_Y_loss: 0.3389 | g_total_loss: 4.9143
Epoch [  980/ 5000] | d_X_loss: 0.4064 | d_Y_loss: 0.5074 | g_total_loss: 3.6083
Epoch [  990/ 5000] | d_X_loss: 0.3401 | d_Y_loss: 0.3954 | g_total_loss: 4.0538
Epoch [ 1000/ 5000] | d_X_loss: 0.2919 | d_Y_loss: 0.4279 | g_total_loss: 3.6796
Saved samples_cyclegan/sample-001000-X-Y.png
Saved samples_cyclegan/sample-001000-Y-X.png
Epoch [ 1010/ 5000] | d_X_loss: 0.3031 | d_Y_loss: 0.3700 | g_total_loss: 4.6336
Epoch [ 1020/ 5000] | d_X_loss: 0.3184 | d_Y_loss: 0.2647 | g_total_loss: 3.9784
Epoch [ 1030/ 5000] | d_X_loss: 0.2268 | d_Y_loss: 0.3803 | g_total_loss: 3.5794
Epoch [ 1040/ 5000] | d_X_loss: 0.2447 | d_Y_loss: 0.5005 | g_total_loss: 4.4106
Epoch [ 1050/ 5000] | d_X_loss: 0.8401 | d_Y_loss: 0.2891 | g_total_loss: 3.2220
Epoch [ 1060/ 5000] | d_X_loss: 0.2661 | d_Y_loss: 0.5486 | g_total_loss: 3.8578
Epoch [ 1070/ 5000] | d_X_loss: 0.1575 | d_Y_loss: 0.3368 | g_total_loss: 3.7620
Epoch [ 1080/ 5000] | d_X_loss: 0.5277 | d_Y_loss: 0.3476 | g_total_loss: 4.6320
Epoch [ 1090/ 5000] | d_X_loss: 0.2854 | d_Y_loss: 0.6827 | g_total_loss: 5.8592
Epoch [ 1100/ 5000] | d_X_loss: 0.1500 | d_Y_loss: 0.3024 | g_total_loss: 4.2922
Saved samples_cyclegan/sample-001100-X-Y.png
Saved samples_cyclegan/sample-001100-Y-X.png
Epoch [ 1110/ 5000] | d_X_loss: 0.4249 | d_Y_loss: 0.3832 | g_total_loss: 5.0263
Epoch [ 1120/ 5000] | d_X_loss: 0.3051 | d_Y_loss: 0.3217 | g_total_loss: 4.7673
Epoch [ 1130/ 5000] | d_X_loss: 0.1602 | d_Y_loss: 0.4292 | g_total_loss: 4.8510
Epoch [ 1140/ 5000] | d_X_loss: 0.2261 | d_Y_loss: 0.3878 | g_total_loss: 4.9399
Epoch [ 1150/ 5000] | d_X_loss: 0.6256 | d_Y_loss: 0.6111 | g_total_loss: 3.6822
Epoch [ 1160/ 5000] | d_X_loss: 0.3390 | d_Y_loss: 0.4185 | g_total_loss: 4.4322
Epoch [ 1170/ 5000] | d_X_loss: 0.3404 | d_Y_loss: 0.3196 | g_total_loss: 4.1720
Epoch [ 1180/ 5000] | d_X_loss: 0.1362 | d_Y_loss: 0.3734 | g_total_loss: 3.7554
Epoch [ 1190/ 5000] | d_X_loss: 0.1873 | d_Y_loss: 0.2879 | g_total_loss: 5.4188
Epoch [ 1200/ 5000] | d_X_loss: 0.2615 | d_Y_loss: 0.3118 | g_total_loss: 4.6369
Saved samples_cyclegan/sample-001200-X-Y.png
Saved samples_cyclegan/sample-001200-Y-X.png
Epoch [ 1210/ 5000] | d_X_loss: 0.2619 | d_Y_loss: 0.4960 | g_total_loss: 5.0052
Epoch [ 1220/ 5000] | d_X_loss: 0.2523 | d_Y_loss: 0.5388 | g_total_loss: 3.4370
Epoch [ 1230/ 5000] | d_X_loss: 0.0792 | d_Y_loss: 0.3374 | g_total_loss: 4.2555
Epoch [ 1240/ 5000] | d_X_loss: 0.3040 | d_Y_loss: 0.2281 | g_total_loss: 3.9562
Epoch [ 1250/ 5000] | d_X_loss: 0.1749 | d_Y_loss: 0.4104 | g_total_loss: 4.5690
Epoch [ 1260/ 5000] | d_X_loss: 0.5008 | d_Y_loss: 0.3729 | g_total_loss: 3.5158
Epoch [ 1270/ 5000] | d_X_loss: 0.4433 | d_Y_loss: 0.3338 | g_total_loss: 5.4495
Epoch [ 1280/ 5000] | d_X_loss: 0.0559 | d_Y_loss: 0.2352 | g_total_loss: 5.9133
Epoch [ 1290/ 5000] | d_X_loss: 0.1741 | d_Y_loss: 0.3768 | g_total_loss: 4.1566
Epoch [ 1300/ 5000] | d_X_loss: 0.0943 | d_Y_loss: 0.3499 | g_total_loss: 4.0777
Saved samples_cyclegan/sample-001300-X-Y.png
Saved samples_cyclegan/sample-001300-Y-X.png
Epoch [ 1310/ 5000] | d_X_loss: 0.1251 | d_Y_loss: 0.2894 | g_total_loss: 4.3142
Epoch [ 1320/ 5000] | d_X_loss: 0.6348 | d_Y_loss: 0.4597 | g_total_loss: 5.0123
Epoch [ 1330/ 5000] | d_X_loss: 0.0859 | d_Y_loss: 0.2392 | g_total_loss: 4.6105
Epoch [ 1340/ 5000] | d_X_loss: 0.2761 | d_Y_loss: 0.4072 | g_total_loss: 4.0423
Epoch [ 1350/ 5000] | d_X_loss: 0.1820 | d_Y_loss: 0.3140 | g_total_loss: 3.7934
Epoch [ 1360/ 5000] | d_X_loss: 0.2512 | d_Y_loss: 0.3837 | g_total_loss: 5.1489
Epoch [ 1370/ 5000] | d_X_loss: 0.1792 | d_Y_loss: 0.2463 | g_total_loss: 4.6263
Epoch [ 1380/ 5000] | d_X_loss: 0.1263 | d_Y_loss: 0.3813 | g_total_loss: 4.6826
Epoch [ 1390/ 5000] | d_X_loss: 0.2200 | d_Y_loss: 0.3260 | g_total_loss: 3.3545
Epoch [ 1400/ 5000] | d_X_loss: 0.2919 | d_Y_loss: 0.3694 | g_total_loss: 3.6609
Saved samples_cyclegan/sample-001400-X-Y.png
Saved samples_cyclegan/sample-001400-Y-X.png
Epoch [ 1410/ 5000] | d_X_loss: 0.3171 | d_Y_loss: 0.4074 | g_total_loss: 4.0604
Epoch [ 1420/ 5000] | d_X_loss: 0.3701 | d_Y_loss: 0.3270 | g_total_loss: 4.5453
Epoch [ 1430/ 5000] | d_X_loss: 0.3715 | d_Y_loss: 0.3159 | g_total_loss: 3.6353
Epoch [ 1440/ 5000] | d_X_loss: 0.1957 | d_Y_loss: 0.4695 | g_total_loss: 4.6301
Epoch [ 1450/ 5000] | d_X_loss: 0.4224 | d_Y_loss: 0.2778 | g_total_loss: 4.4215
Epoch [ 1460/ 5000] | d_X_loss: 0.1514 | d_Y_loss: 0.3414 | g_total_loss: 3.8832
Epoch [ 1470/ 5000] | d_X_loss: 0.1432 | d_Y_loss: 0.3938 | g_total_loss: 4.8257
Epoch [ 1480/ 5000] | d_X_loss: 0.1714 | d_Y_loss: 0.2639 | g_total_loss: 3.9249
Epoch [ 1490/ 5000] | d_X_loss: 0.1074 | d_Y_loss: 0.5596 | g_total_loss: 3.8666
Epoch [ 1500/ 5000] | d_X_loss: 0.0477 | d_Y_loss: 0.3105 | g_total_loss: 4.7386
Saved samples_cyclegan/sample-001500-X-Y.png
Saved samples_cyclegan/sample-001500-Y-X.png
Epoch [ 1510/ 5000] | d_X_loss: 0.0884 | d_Y_loss: 0.3937 | g_total_loss: 3.4954
Epoch [ 1520/ 5000] | d_X_loss: 0.1374 | d_Y_loss: 0.3195 | g_total_loss: 4.1115
Epoch [ 1530/ 5000] | d_X_loss: 0.1054 | d_Y_loss: 0.3064 | g_total_loss: 4.0693
Epoch [ 1540/ 5000] | d_X_loss: 0.2905 | d_Y_loss: 0.3068 | g_total_loss: 4.7480
Epoch [ 1550/ 5000] | d_X_loss: 0.1283 | d_Y_loss: 0.2768 | g_total_loss: 4.3692
Epoch [ 1560/ 5000] | d_X_loss: 0.3148 | d_Y_loss: 0.4182 | g_total_loss: 4.8944
Epoch [ 1570/ 5000] | d_X_loss: 0.1514 | d_Y_loss: 0.2523 | g_total_loss: 4.6974
Epoch [ 1580/ 5000] | d_X_loss: 0.0793 | d_Y_loss: 0.3277 | g_total_loss: 3.9251
Epoch [ 1590/ 5000] | d_X_loss: 0.2691 | d_Y_loss: 0.3203 | g_total_loss: 3.8278
Epoch [ 1600/ 5000] | d_X_loss: 0.1705 | d_Y_loss: 0.1751 | g_total_loss: 4.4696
Saved samples_cyclegan/sample-001600-X-Y.png
Saved samples_cyclegan/sample-001600-Y-X.png
Epoch [ 1610/ 5000] | d_X_loss: 0.1642 | d_Y_loss: 0.4087 | g_total_loss: 3.6415
Epoch [ 1620/ 5000] | d_X_loss: 0.2615 | d_Y_loss: 0.2457 | g_total_loss: 3.9085
Epoch [ 1630/ 5000] | d_X_loss: 0.1344 | d_Y_loss: 0.2719 | g_total_loss: 4.3702
Epoch [ 1640/ 5000] | d_X_loss: 0.1985 | d_Y_loss: 0.1688 | g_total_loss: 3.5986
Epoch [ 1650/ 5000] | d_X_loss: 0.2774 | d_Y_loss: 0.2628 | g_total_loss: 3.9061
Epoch [ 1660/ 5000] | d_X_loss: 0.1998 | d_Y_loss: 0.2409 | g_total_loss: 3.9883
Epoch [ 1670/ 5000] | d_X_loss: 0.0775 | d_Y_loss: 0.2478 | g_total_loss: 3.4808
Epoch [ 1680/ 5000] | d_X_loss: 0.0759 | d_Y_loss: 0.5275 | g_total_loss: 4.0328
Epoch [ 1690/ 5000] | d_X_loss: 0.0513 | d_Y_loss: 0.3662 | g_total_loss: 3.8410
Epoch [ 1700/ 5000] | d_X_loss: 0.3881 | d_Y_loss: 0.1746 | g_total_loss: 3.6850
Saved samples_cyclegan/sample-001700-X-Y.png
Saved samples_cyclegan/sample-001700-Y-X.png
Epoch [ 1710/ 5000] | d_X_loss: 0.1157 | d_Y_loss: 0.2416 | g_total_loss: 4.4485
Epoch [ 1720/ 5000] | d_X_loss: 0.3362 | d_Y_loss: 0.5072 | g_total_loss: 4.2057
Epoch [ 1730/ 5000] | d_X_loss: 0.1912 | d_Y_loss: 0.1723 | g_total_loss: 4.7396
Epoch [ 1740/ 5000] | d_X_loss: 0.1575 | d_Y_loss: 0.2779 | g_total_loss: 4.1059
Epoch [ 1750/ 5000] | d_X_loss: 0.0329 | d_Y_loss: 0.2476 | g_total_loss: 3.5664
Epoch [ 1760/ 5000] | d_X_loss: 0.2553 | d_Y_loss: 0.2012 | g_total_loss: 4.9241
Epoch [ 1770/ 5000] | d_X_loss: 0.1246 | d_Y_loss: 0.2283 | g_total_loss: 4.1061
Epoch [ 1780/ 5000] | d_X_loss: 0.4080 | d_Y_loss: 0.1553 | g_total_loss: 4.7133
Epoch [ 1790/ 5000] | d_X_loss: 0.1346 | d_Y_loss: 0.2821 | g_total_loss: 4.1768
Epoch [ 1800/ 5000] | d_X_loss: 0.2122 | d_Y_loss: 0.2174 | g_total_loss: 4.3433
Saved samples_cyclegan/sample-001800-X-Y.png
Saved samples_cyclegan/sample-001800-Y-X.png
Epoch [ 1810/ 5000] | d_X_loss: 0.1376 | d_Y_loss: 0.2277 | g_total_loss: 4.8251
Epoch [ 1820/ 5000] | d_X_loss: 0.1907 | d_Y_loss: 0.3802 | g_total_loss: 4.4379
Epoch [ 1830/ 5000] | d_X_loss: 0.0748 | d_Y_loss: 0.2716 | g_total_loss: 5.2055
Epoch [ 1840/ 5000] | d_X_loss: 0.1437 | d_Y_loss: 0.2272 | g_total_loss: 4.2563
Epoch [ 1850/ 5000] | d_X_loss: 0.2390 | d_Y_loss: 0.2344 | g_total_loss: 4.7748
Epoch [ 1860/ 5000] | d_X_loss: 0.0557 | d_Y_loss: 0.2051 | g_total_loss: 4.3350
Epoch [ 1870/ 5000] | d_X_loss: 0.1683 | d_Y_loss: 0.3198 | g_total_loss: 3.6913
Epoch [ 1880/ 5000] | d_X_loss: 0.1809 | d_Y_loss: 0.1700 | g_total_loss: 3.7537
Epoch [ 1890/ 5000] | d_X_loss: 0.0719 | d_Y_loss: 0.2254 | g_total_loss: 5.5955
Epoch [ 1900/ 5000] | d_X_loss: 0.0981 | d_Y_loss: 0.2692 | g_total_loss: 4.2295
Saved samples_cyclegan/sample-001900-X-Y.png
Saved samples_cyclegan/sample-001900-Y-X.png
Epoch [ 1910/ 5000] | d_X_loss: 0.0375 | d_Y_loss: 0.2127 | g_total_loss: 3.6687
Epoch [ 1920/ 5000] | d_X_loss: 0.2174 | d_Y_loss: 0.1623 | g_total_loss: 4.4310
Epoch [ 1930/ 5000] | d_X_loss: 0.0407 | d_Y_loss: 0.2951 | g_total_loss: 3.9968
Epoch [ 1940/ 5000] | d_X_loss: 0.0393 | d_Y_loss: 0.1438 | g_total_loss: 3.7050
Epoch [ 1950/ 5000] | d_X_loss: 0.0941 | d_Y_loss: 0.2179 | g_total_loss: 4.2799
Epoch [ 1960/ 5000] | d_X_loss: 0.0543 | d_Y_loss: 0.2252 | g_total_loss: 3.9289
Epoch [ 1970/ 5000] | d_X_loss: 0.1501 | d_Y_loss: 0.2227 | g_total_loss: 4.3058
Epoch [ 1980/ 5000] | d_X_loss: 0.1984 | d_Y_loss: 0.1795 | g_total_loss: 4.3424
Epoch [ 1990/ 5000] | d_X_loss: 0.1681 | d_Y_loss: 0.2072 | g_total_loss: 4.1759
Epoch [ 2000/ 5000] | d_X_loss: 0.0933 | d_Y_loss: 0.1686 | g_total_loss: 4.6926
Saved samples_cyclegan/sample-002000-X-Y.png
Saved samples_cyclegan/sample-002000-Y-X.png
Epoch [ 2010/ 5000] | d_X_loss: 0.0333 | d_Y_loss: 0.2362 | g_total_loss: 4.8680
Epoch [ 2020/ 5000] | d_X_loss: 0.1782 | d_Y_loss: 0.3202 | g_total_loss: 4.0393
Epoch [ 2030/ 5000] | d_X_loss: 0.1749 | d_Y_loss: 0.1664 | g_total_loss: 4.6660
Epoch [ 2040/ 5000] | d_X_loss: 0.1221 | d_Y_loss: 0.1789 | g_total_loss: 4.6476
Epoch [ 2050/ 5000] | d_X_loss: 0.2463 | d_Y_loss: 0.1610 | g_total_loss: 4.4704
Epoch [ 2060/ 5000] | d_X_loss: 0.1938 | d_Y_loss: 0.3327 | g_total_loss: 4.5503
Epoch [ 2070/ 5000] | d_X_loss: 0.1970 | d_Y_loss: 0.3121 | g_total_loss: 4.5201
Epoch [ 2080/ 5000] | d_X_loss: 0.1016 | d_Y_loss: 0.1953 | g_total_loss: 3.9472
Epoch [ 2090/ 5000] | d_X_loss: 0.0744 | d_Y_loss: 0.2256 | g_total_loss: 4.5358
Epoch [ 2100/ 5000] | d_X_loss: 0.1911 | d_Y_loss: 0.2338 | g_total_loss: 4.1335
Saved samples_cyclegan/sample-002100-X-Y.png
Saved samples_cyclegan/sample-002100-Y-X.png
Epoch [ 2110/ 5000] | d_X_loss: 0.1416 | d_Y_loss: 0.2446 | g_total_loss: 4.7728
Epoch [ 2120/ 5000] | d_X_loss: 0.0632 | d_Y_loss: 0.1875 | g_total_loss: 4.2020
Epoch [ 2130/ 5000] | d_X_loss: 0.3268 | d_Y_loss: 0.2708 | g_total_loss: 5.6716
Epoch [ 2140/ 5000] | d_X_loss: 0.1220 | d_Y_loss: 0.1994 | g_total_loss: 4.3549
Epoch [ 2150/ 5000] | d_X_loss: 0.2474 | d_Y_loss: 0.1584 | g_total_loss: 3.7646
Epoch [ 2160/ 5000] | d_X_loss: 0.4700 | d_Y_loss: 0.1503 | g_total_loss: 4.7962
Epoch [ 2170/ 5000] | d_X_loss: 0.0872 | d_Y_loss: 0.1533 | g_total_loss: 4.1516
Epoch [ 2180/ 5000] | d_X_loss: 0.0679 | d_Y_loss: 0.2808 | g_total_loss: 4.5230
Epoch [ 2190/ 5000] | d_X_loss: 0.0445 | d_Y_loss: 0.1978 | g_total_loss: 4.2334
Epoch [ 2200/ 5000] | d_X_loss: 0.1402 | d_Y_loss: 0.7013 | g_total_loss: 4.7846
Saved samples_cyclegan/sample-002200-X-Y.png
Saved samples_cyclegan/sample-002200-Y-X.png
Epoch [ 2210/ 5000] | d_X_loss: 0.0567 | d_Y_loss: 0.2029 | g_total_loss: 4.4709
Epoch [ 2220/ 5000] | d_X_loss: 0.1251 | d_Y_loss: 0.1962 | g_total_loss: 4.3561
Epoch [ 2230/ 5000] | d_X_loss: 0.0955 | d_Y_loss: 0.2245 | g_total_loss: 4.7503
Epoch [ 2240/ 5000] | d_X_loss: 0.0786 | d_Y_loss: 0.0898 | g_total_loss: 6.1525
Epoch [ 2250/ 5000] | d_X_loss: 0.1323 | d_Y_loss: 0.1135 | g_total_loss: 4.5921
Epoch [ 2260/ 5000] | d_X_loss: 0.1523 | d_Y_loss: 0.0722 | g_total_loss: 4.7149
Epoch [ 2270/ 5000] | d_X_loss: 0.0942 | d_Y_loss: 0.1624 | g_total_loss: 4.3998
Epoch [ 2280/ 5000] | d_X_loss: 0.2642 | d_Y_loss: 0.2682 | g_total_loss: 5.8411
Epoch [ 2290/ 5000] | d_X_loss: 0.2491 | d_Y_loss: 0.1379 | g_total_loss: 4.7633
Epoch [ 2300/ 5000] | d_X_loss: 0.3296 | d_Y_loss: 0.1687 | g_total_loss: 4.4254
Saved samples_cyclegan/sample-002300-X-Y.png
Saved samples_cyclegan/sample-002300-Y-X.png
Epoch [ 2310/ 5000] | d_X_loss: 0.1241 | d_Y_loss: 0.2614 | g_total_loss: 5.3157
Epoch [ 2320/ 5000] | d_X_loss: 0.0725 | d_Y_loss: 0.1098 | g_total_loss: 4.2482
Epoch [ 2330/ 5000] | d_X_loss: 0.5474 | d_Y_loss: 0.2615 | g_total_loss: 5.3162
Epoch [ 2340/ 5000] | d_X_loss: 0.0824 | d_Y_loss: 0.2827 | g_total_loss: 4.6666
Epoch [ 2350/ 5000] | d_X_loss: 0.1870 | d_Y_loss: 0.2652 | g_total_loss: 3.7830
Epoch [ 2360/ 5000] | d_X_loss: 0.1802 | d_Y_loss: 0.1450 | g_total_loss: 4.8782
Epoch [ 2370/ 5000] | d_X_loss: 0.0873 | d_Y_loss: 0.2006 | g_total_loss: 3.9929
Epoch [ 2380/ 5000] | d_X_loss: 0.1492 | d_Y_loss: 0.1331 | g_total_loss: 4.1295
Epoch [ 2390/ 5000] | d_X_loss: 0.1453 | d_Y_loss: 0.1767 | g_total_loss: 4.2996
Epoch [ 2400/ 5000] | d_X_loss: 0.1910 | d_Y_loss: 0.2171 | g_total_loss: 5.3485
Saved samples_cyclegan/sample-002400-X-Y.png
Saved samples_cyclegan/sample-002400-Y-X.png
Epoch [ 2410/ 5000] | d_X_loss: 0.1376 | d_Y_loss: 0.1261 | g_total_loss: 4.2639
Epoch [ 2420/ 5000] | d_X_loss: 0.1093 | d_Y_loss: 0.4477 | g_total_loss: 3.3469
Epoch [ 2430/ 5000] | d_X_loss: 0.1029 | d_Y_loss: 0.1386 | g_total_loss: 3.9532
Epoch [ 2440/ 5000] | d_X_loss: 0.3536 | d_Y_loss: 0.1562 | g_total_loss: 4.0891
Epoch [ 2450/ 5000] | d_X_loss: 0.0836 | d_Y_loss: 0.2438 | g_total_loss: 4.3408
Epoch [ 2460/ 5000] | d_X_loss: 0.0341 | d_Y_loss: 0.1828 | g_total_loss: 4.2930
Epoch [ 2470/ 5000] | d_X_loss: 0.1313 | d_Y_loss: 0.1636 | g_total_loss: 3.6994
Epoch [ 2480/ 5000] | d_X_loss: 0.1301 | d_Y_loss: 0.1051 | g_total_loss: 3.8555
Epoch [ 2490/ 5000] | d_X_loss: 0.3004 | d_Y_loss: 0.1780 | g_total_loss: 4.4261
Epoch [ 2500/ 5000] | d_X_loss: 0.0638 | d_Y_loss: 0.1425 | g_total_loss: 4.7720
Saved samples_cyclegan/sample-002500-X-Y.png
Saved samples_cyclegan/sample-002500-Y-X.png
Epoch [ 2510/ 5000] | d_X_loss: 0.1760 | d_Y_loss: 0.1460 | g_total_loss: 5.1665
Epoch [ 2520/ 5000] | d_X_loss: 0.0443 | d_Y_loss: 0.1043 | g_total_loss: 4.4554
Epoch [ 2530/ 5000] | d_X_loss: 0.3293 | d_Y_loss: 0.1476 | g_total_loss: 4.4875
Epoch [ 2540/ 5000] | d_X_loss: 0.0723 | d_Y_loss: 0.1980 | g_total_loss: 4.0720
Epoch [ 2550/ 5000] | d_X_loss: 0.0505 | d_Y_loss: 0.1538 | g_total_loss: 4.4332
Epoch [ 2560/ 5000] | d_X_loss: 0.0411 | d_Y_loss: 0.1682 | g_total_loss: 4.2262
Epoch [ 2570/ 5000] | d_X_loss: 0.3538 | d_Y_loss: 0.1223 | g_total_loss: 5.7081
Epoch [ 2580/ 5000] | d_X_loss: 0.0369 | d_Y_loss: 0.2157 | g_total_loss: 4.9563
Epoch [ 2590/ 5000] | d_X_loss: 0.2625 | d_Y_loss: 0.0573 | g_total_loss: 4.2910
Epoch [ 2600/ 5000] | d_X_loss: 0.1449 | d_Y_loss: 0.2175 | g_total_loss: 4.7638
Saved samples_cyclegan/sample-002600-X-Y.png
Saved samples_cyclegan/sample-002600-Y-X.png
Epoch [ 2610/ 5000] | d_X_loss: 0.0987 | d_Y_loss: 0.3458 | g_total_loss: 4.0175
Epoch [ 2620/ 5000] | d_X_loss: 0.0409 | d_Y_loss: 0.2761 | g_total_loss: 4.6359
Epoch [ 2630/ 5000] | d_X_loss: 0.0483 | d_Y_loss: 0.0924 | g_total_loss: 4.4017
Epoch [ 2640/ 5000] | d_X_loss: 0.0316 | d_Y_loss: 0.1935 | g_total_loss: 4.2667
Epoch [ 2650/ 5000] | d_X_loss: 0.1799 | d_Y_loss: 0.1956 | g_total_loss: 4.7456
Epoch [ 2660/ 5000] | d_X_loss: 0.4747 | d_Y_loss: 0.1531 | g_total_loss: 4.5799
Epoch [ 2670/ 5000] | d_X_loss: 0.0940 | d_Y_loss: 0.1320 | g_total_loss: 4.4498
Epoch [ 2680/ 5000] | d_X_loss: 0.2059 | d_Y_loss: 0.1460 | g_total_loss: 4.5815
Epoch [ 2690/ 5000] | d_X_loss: 0.0363 | d_Y_loss: 0.0898 | g_total_loss: 4.0815
Epoch [ 2700/ 5000] | d_X_loss: 0.1945 | d_Y_loss: 0.1130 | g_total_loss: 3.6456
Saved samples_cyclegan/sample-002700-X-Y.png
Saved samples_cyclegan/sample-002700-Y-X.png
Epoch [ 2710/ 5000] | d_X_loss: 0.1859 | d_Y_loss: 0.0766 | g_total_loss: 5.1669
Epoch [ 2720/ 5000] | d_X_loss: 0.0967 | d_Y_loss: 0.2571 | g_total_loss: 4.6376
Epoch [ 2730/ 5000] | d_X_loss: 0.1156 | d_Y_loss: 0.1381 | g_total_loss: 5.1491
Epoch [ 2740/ 5000] | d_X_loss: 0.0793 | d_Y_loss: 0.1309 | g_total_loss: 4.8896
Epoch [ 2750/ 5000] | d_X_loss: 0.0306 | d_Y_loss: 0.1172 | g_total_loss: 3.7967
Epoch [ 2760/ 5000] | d_X_loss: 0.1095 | d_Y_loss: 0.3280 | g_total_loss: 4.5047
Epoch [ 2770/ 5000] | d_X_loss: 0.1727 | d_Y_loss: 0.1092 | g_total_loss: 4.2602
Epoch [ 2780/ 5000] | d_X_loss: 0.2899 | d_Y_loss: 0.2311 | g_total_loss: 3.3449
Epoch [ 2790/ 5000] | d_X_loss: 0.2248 | d_Y_loss: 0.1119 | g_total_loss: 4.7385
Epoch [ 2800/ 5000] | d_X_loss: 0.0901 | d_Y_loss: 0.1435 | g_total_loss: 4.2638
Saved samples_cyclegan/sample-002800-X-Y.png
Saved samples_cyclegan/sample-002800-Y-X.png
Epoch [ 2810/ 5000] | d_X_loss: 0.1160 | d_Y_loss: 0.1363 | g_total_loss: 4.6891
Epoch [ 2820/ 5000] | d_X_loss: 0.1821 | d_Y_loss: 0.3450 | g_total_loss: 4.9808
Epoch [ 2830/ 5000] | d_X_loss: 0.0711 | d_Y_loss: 0.0881 | g_total_loss: 4.0065
Epoch [ 2840/ 5000] | d_X_loss: 0.1433 | d_Y_loss: 0.1883 | g_total_loss: 3.6761
Epoch [ 2850/ 5000] | d_X_loss: 0.1015 | d_Y_loss: 0.1475 | g_total_loss: 4.6416
Epoch [ 2860/ 5000] | d_X_loss: 0.2114 | d_Y_loss: 0.1150 | g_total_loss: 3.8285
Epoch [ 2870/ 5000] | d_X_loss: 0.0370 | d_Y_loss: 0.0918 | g_total_loss: 4.1321
Epoch [ 2880/ 5000] | d_X_loss: 0.0922 | d_Y_loss: 0.2066 | g_total_loss: 3.6923
Epoch [ 2890/ 5000] | d_X_loss: 0.1436 | d_Y_loss: 0.2650 | g_total_loss: 4.4830
Epoch [ 2900/ 5000] | d_X_loss: 0.1034 | d_Y_loss: 0.1441 | g_total_loss: 4.1410
Saved samples_cyclegan/sample-002900-X-Y.png
Saved samples_cyclegan/sample-002900-Y-X.png
Epoch [ 2910/ 5000] | d_X_loss: 0.1588 | d_Y_loss: 0.1258 | g_total_loss: 4.2779
Epoch [ 2920/ 5000] | d_X_loss: 0.2695 | d_Y_loss: 0.4697 | g_total_loss: 4.1667
Epoch [ 2930/ 5000] | d_X_loss: 0.0461 | d_Y_loss: 0.0774 | g_total_loss: 4.1490
Epoch [ 2940/ 5000] | d_X_loss: 0.1066 | d_Y_loss: 0.0967 | g_total_loss: 4.1177
Epoch [ 2950/ 5000] | d_X_loss: 0.1075 | d_Y_loss: 0.0804 | g_total_loss: 5.0187
Epoch [ 2960/ 5000] | d_X_loss: 0.0867 | d_Y_loss: 0.1154 | g_total_loss: 4.1637
Epoch [ 2970/ 5000] | d_X_loss: 0.4116 | d_Y_loss: 0.1095 | g_total_loss: 3.6927
Epoch [ 2980/ 5000] | d_X_loss: 0.3024 | d_Y_loss: 0.0761 | g_total_loss: 4.9554
Epoch [ 2990/ 5000] | d_X_loss: 0.1043 | d_Y_loss: 0.2615 | g_total_loss: 5.6238
Epoch [ 3000/ 5000] | d_X_loss: 0.0705 | d_Y_loss: 0.1384 | g_total_loss: 3.8776
Saved samples_cyclegan/sample-003000-X-Y.png
Saved samples_cyclegan/sample-003000-Y-X.png
Epoch [ 3010/ 5000] | d_X_loss: 0.2247 | d_Y_loss: 0.0893 | g_total_loss: 3.8898
Epoch [ 3020/ 5000] | d_X_loss: 0.2603 | d_Y_loss: 0.1559 | g_total_loss: 4.4328
Epoch [ 3030/ 5000] | d_X_loss: 0.1059 | d_Y_loss: 0.1714 | g_total_loss: 4.1588
Epoch [ 3040/ 5000] | d_X_loss: 0.3964 | d_Y_loss: 0.1013 | g_total_loss: 4.5799
Epoch [ 3050/ 5000] | d_X_loss: 0.0603 | d_Y_loss: 0.1218 | g_total_loss: 4.1044
Epoch [ 3060/ 5000] | d_X_loss: 0.0478 | d_Y_loss: 0.1601 | g_total_loss: 4.2233
Epoch [ 3070/ 5000] | d_X_loss: 0.0541 | d_Y_loss: 0.1627 | g_total_loss: 4.2394
Epoch [ 3080/ 5000] | d_X_loss: 0.1670 | d_Y_loss: 0.1458 | g_total_loss: 4.0086
Epoch [ 3090/ 5000] | d_X_loss: 0.0827 | d_Y_loss: 0.1414 | g_total_loss: 3.6365
Epoch [ 3100/ 5000] | d_X_loss: 0.0749 | d_Y_loss: 0.0917 | g_total_loss: 4.0094
Saved samples_cyclegan/sample-003100-X-Y.png
Saved samples_cyclegan/sample-003100-Y-X.png
Epoch [ 3110/ 5000] | d_X_loss: 0.0778 | d_Y_loss: 0.1410 | g_total_loss: 5.8936
Epoch [ 3120/ 5000] | d_X_loss: 0.0686 | d_Y_loss: 0.1515 | g_total_loss: 4.8438
Epoch [ 3130/ 5000] | d_X_loss: 0.0584 | d_Y_loss: 0.1835 | g_total_loss: 4.5632
Epoch [ 3140/ 5000] | d_X_loss: 0.0379 | d_Y_loss: 0.1270 | g_total_loss: 4.6428
Epoch [ 3150/ 5000] | d_X_loss: 0.3014 | d_Y_loss: 0.0691 | g_total_loss: 3.9902
Epoch [ 3160/ 5000] | d_X_loss: 0.0638 | d_Y_loss: 0.1000 | g_total_loss: 4.8803
Epoch [ 3170/ 5000] | d_X_loss: 0.1276 | d_Y_loss: 0.1475 | g_total_loss: 4.9656
Epoch [ 3180/ 5000] | d_X_loss: 0.0459 | d_Y_loss: 0.0991 | g_total_loss: 4.7861
Epoch [ 3190/ 5000] | d_X_loss: 0.2268 | d_Y_loss: 0.1019 | g_total_loss: 3.7420
Epoch [ 3200/ 5000] | d_X_loss: 0.4356 | d_Y_loss: 0.1412 | g_total_loss: 4.3467
Saved samples_cyclegan/sample-003200-X-Y.png
Saved samples_cyclegan/sample-003200-Y-X.png
Epoch [ 3210/ 5000] | d_X_loss: 0.1233 | d_Y_loss: 0.0991 | g_total_loss: 4.8010
Epoch [ 3220/ 5000] | d_X_loss: 0.1075 | d_Y_loss: 0.1086 | g_total_loss: 5.1372
Epoch [ 3230/ 5000] | d_X_loss: 0.2040 | d_Y_loss: 0.1742 | g_total_loss: 4.6217
Epoch [ 3240/ 5000] | d_X_loss: 0.0784 | d_Y_loss: 0.0576 | g_total_loss: 4.2618
Epoch [ 3250/ 5000] | d_X_loss: 0.1091 | d_Y_loss: 0.1799 | g_total_loss: 3.6067
Epoch [ 3260/ 5000] | d_X_loss: 0.1292 | d_Y_loss: 0.0915 | g_total_loss: 4.2702
Epoch [ 3270/ 5000] | d_X_loss: 0.1907 | d_Y_loss: 0.2158 | g_total_loss: 5.1472
Epoch [ 3280/ 5000] | d_X_loss: 0.1135 | d_Y_loss: 0.1177 | g_total_loss: 4.0323
Epoch [ 3290/ 5000] | d_X_loss: 0.0499 | d_Y_loss: 0.1536 | g_total_loss: 4.9635
Epoch [ 3300/ 5000] | d_X_loss: 0.1049 | d_Y_loss: 0.1297 | g_total_loss: 4.1212
Saved samples_cyclegan/sample-003300-X-Y.png
Saved samples_cyclegan/sample-003300-Y-X.png
Epoch [ 3310/ 5000] | d_X_loss: 0.1726 | d_Y_loss: 0.1076 | g_total_loss: 4.1433
Epoch [ 3320/ 5000] | d_X_loss: 0.1272 | d_Y_loss: 0.2828 | g_total_loss: 4.6574
Epoch [ 3330/ 5000] | d_X_loss: 0.1917 | d_Y_loss: 0.1394 | g_total_loss: 4.6272
Epoch [ 3340/ 5000] | d_X_loss: 0.1831 | d_Y_loss: 0.2814 | g_total_loss: 4.0338
Epoch [ 3350/ 5000] | d_X_loss: 0.0730 | d_Y_loss: 0.1078 | g_total_loss: 5.2294
Epoch [ 3360/ 5000] | d_X_loss: 0.0612 | d_Y_loss: 0.1329 | g_total_loss: 4.8514
Epoch [ 3370/ 5000] | d_X_loss: 0.0788 | d_Y_loss: 0.1430 | g_total_loss: 4.0522
Epoch [ 3380/ 5000] | d_X_loss: 0.1046 | d_Y_loss: 0.1330 | g_total_loss: 4.7864
Epoch [ 3390/ 5000] | d_X_loss: 0.0533 | d_Y_loss: 0.0816 | g_total_loss: 4.6202
Epoch [ 3400/ 5000] | d_X_loss: 0.0535 | d_Y_loss: 0.1116 | g_total_loss: 3.7733
Saved samples_cyclegan/sample-003400-X-Y.png
Saved samples_cyclegan/sample-003400-Y-X.png
Epoch [ 3410/ 5000] | d_X_loss: 0.1070 | d_Y_loss: 0.1931 | g_total_loss: 3.6801
Epoch [ 3420/ 5000] | d_X_loss: 0.0747 | d_Y_loss: 0.0768 | g_total_loss: 3.9915
Epoch [ 3430/ 5000] | d_X_loss: 0.1534 | d_Y_loss: 0.1340 | g_total_loss: 4.3214
Epoch [ 3440/ 5000] | d_X_loss: 0.2087 | d_Y_loss: 0.0940 | g_total_loss: 3.8852
Epoch [ 3450/ 5000] | d_X_loss: 0.2227 | d_Y_loss: 0.1247 | g_total_loss: 4.3866
Epoch [ 3460/ 5000] | d_X_loss: 0.0693 | d_Y_loss: 0.1129 | g_total_loss: 4.0649
Epoch [ 3470/ 5000] | d_X_loss: 0.0952 | d_Y_loss: 0.1149 | g_total_loss: 4.2796
Epoch [ 3480/ 5000] | d_X_loss: 0.3842 | d_Y_loss: 0.1400 | g_total_loss: 5.4862
Epoch [ 3490/ 5000] | d_X_loss: 0.3548 | d_Y_loss: 0.0642 | g_total_loss: 5.0658
Epoch [ 3500/ 5000] | d_X_loss: 0.2533 | d_Y_loss: 0.0940 | g_total_loss: 3.8458
Saved samples_cyclegan/sample-003500-X-Y.png
Saved samples_cyclegan/sample-003500-Y-X.png
Epoch [ 3510/ 5000] | d_X_loss: 0.1399 | d_Y_loss: 0.1497 | g_total_loss: 4.5953
Epoch [ 3520/ 5000] | d_X_loss: 0.1004 | d_Y_loss: 0.0988 | g_total_loss: 3.9285
Epoch [ 3530/ 5000] | d_X_loss: 0.0738 | d_Y_loss: 0.1074 | g_total_loss: 3.8848
Epoch [ 3540/ 5000] | d_X_loss: 0.1277 | d_Y_loss: 0.0591 | g_total_loss: 4.1688
Epoch [ 3550/ 5000] | d_X_loss: 0.1580 | d_Y_loss: 0.0970 | g_total_loss: 4.0795
Epoch [ 3560/ 5000] | d_X_loss: 0.1890 | d_Y_loss: 0.0660 | g_total_loss: 4.9180
Epoch [ 3570/ 5000] | d_X_loss: 0.1772 | d_Y_loss: 0.0749 | g_total_loss: 5.2289
Epoch [ 3580/ 5000] | d_X_loss: 0.1764 | d_Y_loss: 0.3018 | g_total_loss: 3.9483
Epoch [ 3590/ 5000] | d_X_loss: 0.1094 | d_Y_loss: 0.1633 | g_total_loss: 5.1895
Epoch [ 3600/ 5000] | d_X_loss: 0.7304 | d_Y_loss: 0.1362 | g_total_loss: 5.5554
Saved samples_cyclegan/sample-003600-X-Y.png
Saved samples_cyclegan/sample-003600-Y-X.png
Epoch [ 3610/ 5000] | d_X_loss: 0.2370 | d_Y_loss: 0.2824 | g_total_loss: 3.6826
Epoch [ 3620/ 5000] | d_X_loss: 0.1516 | d_Y_loss: 0.1436 | g_total_loss: 4.1809
Epoch [ 3630/ 5000] | d_X_loss: 0.1537 | d_Y_loss: 0.0949 | g_total_loss: 3.9242
Epoch [ 3640/ 5000] | d_X_loss: 0.1307 | d_Y_loss: 0.3057 | g_total_loss: 3.7898
Epoch [ 3650/ 5000] | d_X_loss: 0.0919 | d_Y_loss: 0.1630 | g_total_loss: 4.8929
Epoch [ 3660/ 5000] | d_X_loss: 0.0541 | d_Y_loss: 0.1059 | g_total_loss: 3.8275
Epoch [ 3670/ 5000] | d_X_loss: 0.5577 | d_Y_loss: 0.0677 | g_total_loss: 3.6050
Epoch [ 3680/ 5000] | d_X_loss: 0.1420 | d_Y_loss: 0.1783 | g_total_loss: 4.9517
Epoch [ 3690/ 5000] | d_X_loss: 0.1274 | d_Y_loss: 0.2998 | g_total_loss: 3.9747
Epoch [ 3700/ 5000] | d_X_loss: 0.0760 | d_Y_loss: 0.1001 | g_total_loss: 4.2908
Saved samples_cyclegan/sample-003700-X-Y.png
Saved samples_cyclegan/sample-003700-Y-X.png
Epoch [ 3710/ 5000] | d_X_loss: 0.0812 | d_Y_loss: 0.1251 | g_total_loss: 4.1598
Epoch [ 3720/ 5000] | d_X_loss: 0.0643 | d_Y_loss: 0.0871 | g_total_loss: 5.8686
Epoch [ 3730/ 5000] | d_X_loss: 0.0584 | d_Y_loss: 0.1449 | g_total_loss: 4.3791
Epoch [ 3740/ 5000] | d_X_loss: 0.0813 | d_Y_loss: 0.1506 | g_total_loss: 4.3048
Epoch [ 3750/ 5000] | d_X_loss: 0.1765 | d_Y_loss: 0.0747 | g_total_loss: 4.6965
Epoch [ 3760/ 5000] | d_X_loss: 0.0288 | d_Y_loss: 0.1099 | g_total_loss: 4.2973
Epoch [ 3770/ 5000] | d_X_loss: 0.1600 | d_Y_loss: 0.0906 | g_total_loss: 4.9300
Epoch [ 3780/ 5000] | d_X_loss: 0.1526 | d_Y_loss: 0.1588 | g_total_loss: 4.7974
Epoch [ 3790/ 5000] | d_X_loss: 0.0794 | d_Y_loss: 0.0816 | g_total_loss: 4.4884
Epoch [ 3800/ 5000] | d_X_loss: 0.1238 | d_Y_loss: 0.4368 | g_total_loss: 3.4185
Saved samples_cyclegan/sample-003800-X-Y.png
Saved samples_cyclegan/sample-003800-Y-X.png
Epoch [ 3810/ 5000] | d_X_loss: 0.0715 | d_Y_loss: 0.0834 | g_total_loss: 4.0756
Epoch [ 3820/ 5000] | d_X_loss: 0.0980 | d_Y_loss: 0.0874 | g_total_loss: 5.1019
Epoch [ 3830/ 5000] | d_X_loss: 0.0950 | d_Y_loss: 0.1321 | g_total_loss: 4.5648
Epoch [ 3840/ 5000] | d_X_loss: 0.1553 | d_Y_loss: 0.0740 | g_total_loss: 4.2955
Epoch [ 3850/ 5000] | d_X_loss: 0.1179 | d_Y_loss: 0.1948 | g_total_loss: 5.0265
Epoch [ 3860/ 5000] | d_X_loss: 0.1045 | d_Y_loss: 0.1118 | g_total_loss: 4.4115
Epoch [ 3870/ 5000] | d_X_loss: 0.1531 | d_Y_loss: 0.1057 | g_total_loss: 4.2018
Epoch [ 3880/ 5000] | d_X_loss: 0.0970 | d_Y_loss: 0.1739 | g_total_loss: 4.2422
Epoch [ 3890/ 5000] | d_X_loss: 0.0510 | d_Y_loss: 0.1159 | g_total_loss: 4.2841
Epoch [ 3900/ 5000] | d_X_loss: 0.1509 | d_Y_loss: 0.1186 | g_total_loss: 3.7130
Saved samples_cyclegan/sample-003900-X-Y.png
Saved samples_cyclegan/sample-003900-Y-X.png
Epoch [ 3910/ 5000] | d_X_loss: 0.0871 | d_Y_loss: 0.1423 | g_total_loss: 4.4217
Epoch [ 3920/ 5000] | d_X_loss: 0.0866 | d_Y_loss: 0.1350 | g_total_loss: 4.7888
Epoch [ 3930/ 5000] | d_X_loss: 0.1539 | d_Y_loss: 0.0892 | g_total_loss: 4.1321
Epoch [ 3940/ 5000] | d_X_loss: 0.0593 | d_Y_loss: 0.1401 | g_total_loss: 5.1609
Epoch [ 3950/ 5000] | d_X_loss: 0.0706 | d_Y_loss: 0.1207 | g_total_loss: 3.6333
Epoch [ 3960/ 5000] | d_X_loss: 0.1394 | d_Y_loss: 0.0631 | g_total_loss: 4.4448
Epoch [ 3970/ 5000] | d_X_loss: 0.0255 | d_Y_loss: 0.1283 | g_total_loss: 4.5546
Epoch [ 3980/ 5000] | d_X_loss: 0.1671 | d_Y_loss: 0.0935 | g_total_loss: 4.8851
Epoch [ 3990/ 5000] | d_X_loss: 0.1063 | d_Y_loss: 0.2048 | g_total_loss: 3.6794
Epoch [ 4000/ 5000] | d_X_loss: 0.1753 | d_Y_loss: 0.0759 | g_total_loss: 3.4436
Saved samples_cyclegan/sample-004000-X-Y.png
Saved samples_cyclegan/sample-004000-Y-X.png
Epoch [ 4010/ 5000] | d_X_loss: 0.0860 | d_Y_loss: 0.0817 | g_total_loss: 4.1860
Epoch [ 4020/ 5000] | d_X_loss: 0.0430 | d_Y_loss: 0.0541 | g_total_loss: 4.1309
Epoch [ 4030/ 5000] | d_X_loss: 0.1038 | d_Y_loss: 0.1465 | g_total_loss: 3.6894
Epoch [ 4040/ 5000] | d_X_loss: 0.0861 | d_Y_loss: 0.0753 | g_total_loss: 4.4505
Epoch [ 4050/ 5000] | d_X_loss: 0.1774 | d_Y_loss: 0.0644 | g_total_loss: 4.8056
Epoch [ 4060/ 5000] | d_X_loss: 0.1413 | d_Y_loss: 0.0767 | g_total_loss: 4.4207
Epoch [ 4070/ 5000] | d_X_loss: 0.1160 | d_Y_loss: 0.0711 | g_total_loss: 4.3466
Epoch [ 4080/ 5000] | d_X_loss: 0.1316 | d_Y_loss: 0.0919 | g_total_loss: 4.0228
Epoch [ 4090/ 5000] | d_X_loss: 0.6149 | d_Y_loss: 0.1761 | g_total_loss: 6.0007
Epoch [ 4100/ 5000] | d_X_loss: 0.1318 | d_Y_loss: 0.1067 | g_total_loss: 4.5318
Saved samples_cyclegan/sample-004100-X-Y.png
Saved samples_cyclegan/sample-004100-Y-X.png
Epoch [ 4110/ 5000] | d_X_loss: 0.0646 | d_Y_loss: 0.1486 | g_total_loss: 5.2528
Epoch [ 4120/ 5000] | d_X_loss: 0.0869 | d_Y_loss: 0.1030 | g_total_loss: 4.1287
Epoch [ 4130/ 5000] | d_X_loss: 0.2355 | d_Y_loss: 0.1292 | g_total_loss: 4.9262
Epoch [ 4140/ 5000] | d_X_loss: 0.1106 | d_Y_loss: 0.0883 | g_total_loss: 4.6865
Epoch [ 4150/ 5000] | d_X_loss: 0.1354 | d_Y_loss: 0.1787 | g_total_loss: 4.2359
Epoch [ 4160/ 5000] | d_X_loss: 0.0448 | d_Y_loss: 0.1212 | g_total_loss: 4.6215
Epoch [ 4170/ 5000] | d_X_loss: 0.2562 | d_Y_loss: 0.0691 | g_total_loss: 4.8846
Epoch [ 4180/ 5000] | d_X_loss: 0.0891 | d_Y_loss: 0.1247 | g_total_loss: 4.2906
Epoch [ 4190/ 5000] | d_X_loss: 0.0655 | d_Y_loss: 0.1162 | g_total_loss: 4.7743
Epoch [ 4200/ 5000] | d_X_loss: 0.1498 | d_Y_loss: 0.0521 | g_total_loss: 4.6032
Saved samples_cyclegan/sample-004200-X-Y.png
Saved samples_cyclegan/sample-004200-Y-X.png
Epoch [ 4210/ 5000] | d_X_loss: 0.1040 | d_Y_loss: 0.1311 | g_total_loss: 3.8046
Epoch [ 4220/ 5000] | d_X_loss: 0.1826 | d_Y_loss: 0.1252 | g_total_loss: 3.4846
Epoch [ 4230/ 5000] | d_X_loss: 0.0856 | d_Y_loss: 0.1516 | g_total_loss: 4.4240
Epoch [ 4240/ 5000] | d_X_loss: 0.1000 | d_Y_loss: 0.0592 | g_total_loss: 4.2267
Epoch [ 4250/ 5000] | d_X_loss: 0.1977 | d_Y_loss: 0.1427 | g_total_loss: 5.1551
Epoch [ 4260/ 5000] | d_X_loss: 0.1430 | d_Y_loss: 0.1096 | g_total_loss: 3.8701
Epoch [ 4270/ 5000] | d_X_loss: 0.0537 | d_Y_loss: 0.3261 | g_total_loss: 5.5025
Epoch [ 4280/ 5000] | d_X_loss: 0.1446 | d_Y_loss: 0.0613 | g_total_loss: 4.0573
Epoch [ 4290/ 5000] | d_X_loss: 0.1094 | d_Y_loss: 0.1341 | g_total_loss: 3.9082
Epoch [ 4300/ 5000] | d_X_loss: 0.1374 | d_Y_loss: 0.1094 | g_total_loss: 4.6893
Saved samples_cyclegan/sample-004300-X-Y.png
Saved samples_cyclegan/sample-004300-Y-X.png
Epoch [ 4310/ 5000] | d_X_loss: 0.0893 | d_Y_loss: 0.0560 | g_total_loss: 4.8321
Epoch [ 4320/ 5000] | d_X_loss: 0.0418 | d_Y_loss: 0.2868 | g_total_loss: 4.8501
Epoch [ 4330/ 5000] | d_X_loss: 0.0975 | d_Y_loss: 0.0890 | g_total_loss: 5.6154
Epoch [ 4340/ 5000] | d_X_loss: 0.0836 | d_Y_loss: 0.1671 | g_total_loss: 3.6397
Epoch [ 4350/ 5000] | d_X_loss: 0.0871 | d_Y_loss: 0.0516 | g_total_loss: 4.2988
Epoch [ 4360/ 5000] | d_X_loss: 0.2107 | d_Y_loss: 0.1220 | g_total_loss: 3.4372
Epoch [ 4370/ 5000] | d_X_loss: 0.1277 | d_Y_loss: 0.1403 | g_total_loss: 4.2482
Epoch [ 4380/ 5000] | d_X_loss: 0.1437 | d_Y_loss: 0.1018 | g_total_loss: 4.6115
Epoch [ 4390/ 5000] | d_X_loss: 0.1473 | d_Y_loss: 0.1227 | g_total_loss: 4.3364
Epoch [ 4400/ 5000] | d_X_loss: 0.1599 | d_Y_loss: 0.0511 | g_total_loss: 3.9241
Saved samples_cyclegan/sample-004400-X-Y.png
Saved samples_cyclegan/sample-004400-Y-X.png
Epoch [ 4410/ 5000] | d_X_loss: 0.1115 | d_Y_loss: 0.0971 | g_total_loss: 3.4760
Epoch [ 4420/ 5000] | d_X_loss: 0.3367 | d_Y_loss: 0.1568 | g_total_loss: 3.7299
Epoch [ 4430/ 5000] | d_X_loss: 0.0379 | d_Y_loss: 0.1221 | g_total_loss: 4.2112
Epoch [ 4440/ 5000] | d_X_loss: 0.1183 | d_Y_loss: 0.2574 | g_total_loss: 3.4291
Epoch [ 4450/ 5000] | d_X_loss: 0.0952 | d_Y_loss: 0.0503 | g_total_loss: 4.5716
Epoch [ 4460/ 5000] | d_X_loss: 0.0544 | d_Y_loss: 0.0919 | g_total_loss: 3.5468
Epoch [ 4470/ 5000] | d_X_loss: 0.0409 | d_Y_loss: 0.0807 | g_total_loss: 4.1918
Epoch [ 4480/ 5000] | d_X_loss: 0.0675 | d_Y_loss: 0.0806 | g_total_loss: 3.9437
Epoch [ 4490/ 5000] | d_X_loss: 0.0542 | d_Y_loss: 0.3433 | g_total_loss: 4.9468
Epoch [ 4500/ 5000] | d_X_loss: 0.1246 | d_Y_loss: 0.1246 | g_total_loss: 4.2864
Saved samples_cyclegan/sample-004500-X-Y.png
Saved samples_cyclegan/sample-004500-Y-X.png
Epoch [ 4510/ 5000] | d_X_loss: 0.0456 | d_Y_loss: 0.0662 | g_total_loss: 3.8951
Epoch [ 4520/ 5000] | d_X_loss: 0.1466 | d_Y_loss: 0.1061 | g_total_loss: 4.2623
Epoch [ 4530/ 5000] | d_X_loss: 0.1858 | d_Y_loss: 0.1125 | g_total_loss: 4.1540
Epoch [ 4540/ 5000] | d_X_loss: 0.2086 | d_Y_loss: 0.1645 | g_total_loss: 5.0071
Epoch [ 4550/ 5000] | d_X_loss: 0.0475 | d_Y_loss: 0.1573 | g_total_loss: 4.0461
Epoch [ 4560/ 5000] | d_X_loss: 0.0543 | d_Y_loss: 0.0596 | g_total_loss: 4.1790
Epoch [ 4570/ 5000] | d_X_loss: 0.2372 | d_Y_loss: 0.0762 | g_total_loss: 4.5518
Epoch [ 4580/ 5000] | d_X_loss: 0.0424 | d_Y_loss: 0.0426 | g_total_loss: 4.1357
Epoch [ 4590/ 5000] | d_X_loss: 0.0426 | d_Y_loss: 0.0950 | g_total_loss: 4.7793
Epoch [ 4600/ 5000] | d_X_loss: 0.0890 | d_Y_loss: 0.0622 | g_total_loss: 4.6912
Saved samples_cyclegan/sample-004600-X-Y.png
Saved samples_cyclegan/sample-004600-Y-X.png
Epoch [ 4610/ 5000] | d_X_loss: 0.5445 | d_Y_loss: 0.0917 | g_total_loss: 3.9516
Epoch [ 4620/ 5000] | d_X_loss: 0.1591 | d_Y_loss: 0.0742 | g_total_loss: 4.5919
Epoch [ 4630/ 5000] | d_X_loss: 0.2340 | d_Y_loss: 0.1350 | g_total_loss: 3.3519
Epoch [ 4640/ 5000] | d_X_loss: 0.0527 | d_Y_loss: 0.0978 | g_total_loss: 3.9946
Epoch [ 4650/ 5000] | d_X_loss: 0.1486 | d_Y_loss: 0.1306 | g_total_loss: 3.8362
Epoch [ 4660/ 5000] | d_X_loss: 0.0555 | d_Y_loss: 0.1108 | g_total_loss: 4.8094
Epoch [ 4670/ 5000] | d_X_loss: 0.0898 | d_Y_loss: 0.0819 | g_total_loss: 4.3428
Epoch [ 4680/ 5000] | d_X_loss: 0.0289 | d_Y_loss: 0.0562 | g_total_loss: 4.4434
Epoch [ 4690/ 5000] | d_X_loss: 0.2370 | d_Y_loss: 0.1726 | g_total_loss: 4.7790
Epoch [ 4700/ 5000] | d_X_loss: 0.0955 | d_Y_loss: 0.0656 | g_total_loss: 3.8618
Saved samples_cyclegan/sample-004700-X-Y.png
Saved samples_cyclegan/sample-004700-Y-X.png
Epoch [ 4710/ 5000] | d_X_loss: 0.1227 | d_Y_loss: 0.0584 | g_total_loss: 3.9140
Epoch [ 4720/ 5000] | d_X_loss: 0.1250 | d_Y_loss: 0.2179 | g_total_loss: 5.2313
Epoch [ 4730/ 5000] | d_X_loss: 0.1197 | d_Y_loss: 0.1122 | g_total_loss: 3.6917
Epoch [ 4740/ 5000] | d_X_loss: 0.1632 | d_Y_loss: 0.0421 | g_total_loss: 4.2797
Epoch [ 4750/ 5000] | d_X_loss: 0.0860 | d_Y_loss: 0.1660 | g_total_loss: 5.0687
Epoch [ 4760/ 5000] | d_X_loss: 0.1227 | d_Y_loss: 0.0769 | g_total_loss: 3.8684
Epoch [ 4770/ 5000] | d_X_loss: 0.0943 | d_Y_loss: 0.2790 | g_total_loss: 3.7215
Epoch [ 4780/ 5000] | d_X_loss: 0.1568 | d_Y_loss: 0.2051 | g_total_loss: 3.1853
Epoch [ 4790/ 5000] | d_X_loss: 0.0403 | d_Y_loss: 0.1301 | g_total_loss: 3.6019
Epoch [ 4800/ 5000] | d_X_loss: 0.0698 | d_Y_loss: 0.0498 | g_total_loss: 3.8399
Saved samples_cyclegan/sample-004800-X-Y.png
Saved samples_cyclegan/sample-004800-Y-X.png
Epoch [ 4810/ 5000] | d_X_loss: 0.2133 | d_Y_loss: 0.0699 | g_total_loss: 4.1733
Epoch [ 4820/ 5000] | d_X_loss: 0.1387 | d_Y_loss: 0.0967 | g_total_loss: 3.9381
Epoch [ 4830/ 5000] | d_X_loss: 0.1095 | d_Y_loss: 0.1677 | g_total_loss: 3.9611
Epoch [ 4840/ 5000] | d_X_loss: 0.0496 | d_Y_loss: 0.2055 | g_total_loss: 3.7030
Epoch [ 4850/ 5000] | d_X_loss: 0.3912 | d_Y_loss: 0.0648 | g_total_loss: 5.1158
Epoch [ 4860/ 5000] | d_X_loss: 0.1122 | d_Y_loss: 0.0772 | g_total_loss: 3.7025
Epoch [ 4870/ 5000] | d_X_loss: 0.1387 | d_Y_loss: 0.1331 | g_total_loss: 4.1720
Epoch [ 4880/ 5000] | d_X_loss: 0.1710 | d_Y_loss: 0.1307 | g_total_loss: 5.4077
Epoch [ 4890/ 5000] | d_X_loss: 0.0372 | d_Y_loss: 0.0723 | g_total_loss: 4.5116
Epoch [ 4900/ 5000] | d_X_loss: 0.5738 | d_Y_loss: 0.0567 | g_total_loss: 3.5161
Saved samples_cyclegan/sample-004900-X-Y.png
Saved samples_cyclegan/sample-004900-Y-X.png
Epoch [ 4910/ 5000] | d_X_loss: 0.0958 | d_Y_loss: 0.2133 | g_total_loss: 4.1006
Epoch [ 4920/ 5000] | d_X_loss: 0.1371 | d_Y_loss: 0.1277 | g_total_loss: 4.3962
Epoch [ 4930/ 5000] | d_X_loss: 0.0501 | d_Y_loss: 0.2209 | g_total_loss: 3.4196
Epoch [ 4940/ 5000] | d_X_loss: 0.2996 | d_Y_loss: 0.1622 | g_total_loss: 4.4298
Epoch [ 4950/ 5000] | d_X_loss: 0.2639 | d_Y_loss: 0.1948 | g_total_loss: 3.4918
Epoch [ 4960/ 5000] | d_X_loss: 0.1806 | d_Y_loss: 0.0744 | g_total_loss: 3.5097
Epoch [ 4970/ 5000] | d_X_loss: 0.1202 | d_Y_loss: 0.0657 | g_total_loss: 4.3457
Epoch [ 4980/ 5000] | d_X_loss: 0.1330 | d_Y_loss: 0.0644 | g_total_loss: 4.6230
Epoch [ 4990/ 5000] | d_X_loss: 0.2471 | d_Y_loss: 0.0905 | g_total_loss: 5.3341
Epoch [ 5000/ 5000] | d_X_loss: 0.1521 | d_Y_loss: 0.0418 | g_total_loss: 4.1643
Saved samples_cyclegan/sample-005000-X-Y.png
Saved samples_cyclegan/sample-005000-Y-X.png

Tips on Training and Loss Patterns

A lot of experimentation goes into finding the best hyperparameters such that the generators and discriminators don't overpower each other. It's often a good starting point to look at existing papers to find what has worked in previous experiments, I'd recommend this DCGAN paper in addition to the original CycleGAN paper to see what worked for them. Then, you can try your own experiments based off of a good foundation.

Discriminator Losses

When you display the generator and discriminator losses you should see that there is always some discriminator loss; recall that we are trying to design a model that can generate good "fake" images. So, the ideal discriminator will not be able to tell the difference between real and fake images and, as such, will always have some loss. You should also see that $D_X$ and $D_Y$ are roughly at the same loss levels; if they are not, this indicates that your training is favoring one type of discriminator over the and you may need to look at biases in your models or data.

Generator Loss

The generator's loss should start significantly higher than the discriminator losses because it is accounting for the loss of both generators and weighted reconstruction errors. You should see this loss decrease a lot at the start of training because initial, generated images are often far-off from being good fakes. After some time it may level off; this is normal since the generator and discriminator are both improving as they train. If you see that the loss is jumping around a lot, over time, you may want to try decreasing your learning rates or changing your cycle consistency loss to be a little more/less weighted.

In [22]:
fig, ax = plt.subplots(figsize=(12,8))
losses = np.array(losses)
plt.plot(losses.T[0], label='Discriminator, X', alpha=0.5)
plt.plot(losses.T[1], label='Discriminator, Y', alpha=0.5)
plt.plot(losses.T[2], label='Generators', alpha=0.5)
plt.title("Training Losses")
plt.legend()
Out[22]:
<matplotlib.legend.Legend at 0x7f7eb88c39e8>

Evaluate the Result!

As you trained this model, you may have chosen to sample and save the results of your generated images after a certain number of training iterations. This gives you a way to see whether or not your Generators are creating good fake images. For example, the image below depicts real images in the $Y$ set, and the corresponding generated images during different points in the training process. You can see that the generator starts out creating very noisy, fake images, but begins to converge to better representations as it trains (though, not perfect).

Below, you've been given a helper function for displaying generated samples based on the passed in training iteration.

In [23]:
import matplotlib.image as mpimg

# helper visualization code
def view_samples(iteration, sample_dir='samples_cyclegan'):
    
    # samples are named by iteration
    path_XtoY = os.path.join(sample_dir, 'sample-{:06d}-X-Y.png'.format(iteration))
    path_YtoX = os.path.join(sample_dir, 'sample-{:06d}-Y-X.png'.format(iteration))
    
    # read in those samples
    try: 
        x2y = mpimg.imread(path_XtoY)
        y2x = mpimg.imread(path_YtoX)
    except:
        print('Invalid number of iterations.')
    
    fig, (ax1, ax2) = plt.subplots(figsize=(18,20), nrows=2, ncols=1, sharey=True, sharex=True)
    ax1.imshow(x2y)
    ax1.set_title('X to Y')
    ax2.imshow(y2x)
    ax2.set_title('Y to X')
In [24]:
# view samples at iteration 100
view_samples(100, 'samples_cyclegan')
In [25]:
# view samples at iteration 1000
view_samples(1000, 'samples_cyclegan')
In [26]:
view_samples(5000,'samples_cyclegan')

Further Challenges and Directions

  • One shortcoming of this model is that it produces fairly low-resolution images; this is an ongoing area of research; you can read about a higher-resolution formulation that uses a multi-scale generator model, in this paper.
  • Relatedly, we may want to process these as larger (say 256x256) images at first, to take advantage of high-res data.
  • It may help your model to converge faster, if you initialize the weights in your network.
  • This model struggles with matching colors exactly. This is because, if $G_{YtoX}$ and $G_{XtoY}$ may change the tint of an image; the cycle consistency loss may not be affected and can still be small. You could choose to introduce a new, color-based loss term that compares $G_{YtoX}(y)$ and $y$, and $G_{XtoY}(x)$ and $x$, but then this becomes a supervised learning approach.
  • This unsupervised approach also struggles with geometric changes, like changing the apparent size of individual object in an image, so it is best suited for stylistic transformations.
  • For creating different kinds of models or trying out the Pix2Pix Architecture, this Github repository which implements CycleGAN and Pix2Pix in PyTorch is a great resource.

Once you are satified with your model, you are ancouraged to test it on a different dataset to see if it can find different types of mappings!


Different datasets for download

You can download a variety of datasets used in the Pix2Pix and CycleGAN papers, by following instructions in the associated Github repository. You'll just need to make sure that the data directories are named and organized correctly to load in that data.